I am trying to take an input from the user and using the methods of the string module, I want to translate the input to the encrypted text as per the code.
I have tried the same thing three times and still I am getting the error that says: "ValueError: the first two maketrans arguments must have equal length"
Although, in my code I have already checked for the length and both come out to be same.
I am using Python 3.x
# Trial 3
import string
in_text = string.ascii_lowercase
out_text = (string.digits * 2) + string.digits[0:6]
print(len(in_text))
print(len(out_text))
translated_text = str.maketrans(usr_in, usr_out)
my_str = input().lower()
print(my_str.translate(translated_text))
I expect to receive the result to be a text that maps the ascii to the numbers and whenever I input a string, I get an encrypted output.
If I understand you correctly, you want to map lower ascii to digits
you should do it like this
import string
in_text = string.ascii_lowercase
out_text = string.digits * 2 + string.digits[0: 6]
translated_text = str.maketrans(in_text, out_text)
my_str = input().lower()
print(my_str.translate(translated_text))
OUTPUT:
λ python3 s.py
hello, world
74114, 24713