Convert input letter to different letter [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am new to python (pardon my bad terminology). I cannot find a solution to my problem.
I am trying to make a simple encryption system. I want to convert the characters of user input to specific characters. For example: ABC would turn into ZYX.
Can anyone help me with this? Thanks.

assuming you just want a simple substitution cipher you can use the translate function:
# in python3:
# table = str.maketrans('ABC', 'ZYX')
# in python2:
from string import maketrans
table = maketrans('ABC', 'ZYX') # add the rest of the alphabet and the desired
# subsitutions
print('CBA'.translate(table))
# output: 'XYZ'

Related

I want to remove the first part of this string however the number changes [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
Improve this question
I want to remove the first 3 numbers of any string that I put in the input.
response = input("Insert String: ")
If I were to put any string in the response it would print it with the first 3 characters removed.
You can use string slicing.
response=input("Insert string:")[3:]
For more information on how slicing works, check out Understanding slicing on Stack. Happy coding!
Try:
response = input("Insert String: ")
prefixStr = response[:2]
last_3_chars = response[-3:]
print(last_3_chars, prefixStr, sep='\t')
Maybe? I'm not sure exactly what you mean. Please clarify your request.

i want to write a python program that converts an integer to its corresponding month [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to add a error message if it exceeds 12 or if a character is entered without any if statements. here is what I have written so far:
import calender
def get_mont_name(month_number):
try:
return calender.month_name[month_number]
except IndexError:
print("'[]' is not a valid month number".format(month_number))
Your code is really close to working!
Firstly, you've spelt calendar wrong, but I assume this is just a typo.
You've slightly misused format() which is probably causing your issue. Replacing your print statement with the following should fix it:
print("{num} is not a valid month number".format(num = month_number))
The curly brackets allow the format() method to identify the parts of the string you'd like to modify.
I hope this helps!

Easy way to extract multiple dates from string without spaces? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am looking for a way to automatically extract dates from a string, but following each other without a delimiter
For example my string is: \n-\n24-04-201923-04-201922-04-201921-04-201920-04-201919-04-201918-04-2019
How can I get this output:
24-04-2019
23-04-2019
22-04-2019
21-04-2019
20-04-2019
19-04-2019
18-04-2019
Any help would be appreciated!
Given that they're all of equal length, you can just clear the \n's then use textwrap:
import textwrap
print(textwrap.wrap(my_string, 10))
You can remove \n's using strip():
my_string = my_string.strip()
You can use this code also.
string='\n-\n24-04-201923-04-201922-04-201921-04-201920-04-201919-04-201918-04-2019'
newStr=string[3:]
for char in range(0,len(newStr),10):
print newStr[char:char+10]
Here's the output
24-04-2019
23-04-2019
22-04-2019
21-04-2019
20-04-2019
19-04-2019
18-04-2019

remove hex value from string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How do I remove the hex value from a string in Python 2.7? Here is the string,
\xffDSI\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x01\x00\x08\x00\x00\x00\x00\x00\x00\x00#\x00\x00\x00#\x00\x00\x00\x01\x04\xb3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x01\x00\x04\x00\x02\x00\x01\x00\x01\x00\x02\x00\x06\x00\x06"\x00\x00\x00\x00c\x01,\x00\x00\x06&\x00\x00\x00\x01\x01,\x00\x00\x06\'\x00\x00\x11\x98\x00\x19\x00\x00\x00(\x00\x00\x00\x00\x00\x0011_w\x00\x00\x00\x00\x00\x006\x00A\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01,\x00\x00\x17\xbf\x00\x00\x11\x98\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
#b4
,sudd5ly1
!
toddl]
0
able
to
use
a
comput]
to
play
games4
\x00$\x00\x00\x018\x00\x00\x00\x00\x00\x01\x00\x19\x00\x02\x00\x03\x00\x04\x00\x05\x00\x1d\x00\x1f\x00\x06\x00\x07\x00\x08\x00\t\x00'],
['\x00\x0b\x00\x0c\x00\r\x00\x1b\x00\x0e\x00\x0f\x00\x10\x00\x13\x00\x11\x00\x14\x00\x1c\x00\x18\x00
I want to display only #b4 to games4. All the hex values should be removed. Thank you.
What I am trying to do is to read in the file type *.dxb, which display braille font. I was able to read the file but the output showed me all those \xffDSI\x00... and then #b4 ,sudd5ly1
The #b4 ,sudd5ly1 is only the part that I want the output to show so that I can do a comparison with other file.
Thank you again.
You can use something like this:
import string
s = '\xffDSI....'
cleaned = ''.join(c for c in s if c in string.printable)
This uses printable as the definition of "not a hex value", though it does include \x0b and \x0c (both printable whitespace characters).

Python: remove characters from a string? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I took a python course back when i was in high school but now I barely remember anything about it. I'm bored today and though I should try some python exercises.
Example:
string = '3dc8uo8c33a v8c08oizl6ga'
The code needs to remove 3d 8u 8c ... ect
so that the
answer = 'coca cola'
Assuming the rule is "split the string along whitespace, then take every third letter of the words, and add them back together", you can use
>>> string = '3dc8uo8cc33a v8c08oizl6ga'
>>> " ".join("".join(s[2::3]) for s in string.split())
'coca cola'

Categories