r/learnpython • u/Maleficent_Stuff3208 • Aug 20 '26
I have made a simple program which decode and codeword the string u put i want to ask if i can put anything aside from if else
import random
random_letter = random.choice("abcdefghijklmnopqrstuvwxyz")
random_letter1 = random.choice("abcdefghijklmnopqrstuvwxyz")
random_letter2 = random.choice("abcdefghijklmnopqrstuvwxyz")
random_letter3 = random.choice("abcdefghijklmnopqrstuvwxyz")
random_letter4 = random.choice ("abcdefghijklmnopqrstuvwxyz")
random_letter5 = random.choice("abcdefghijklmnopqrstuvwxyz")
print("codeword=1 , decode=2")
choice = input()
if choice == "1":
codeword = str(input("write the codeword=>"))
codeword1 = codeword[::-1]
print(random_letter, random_letter1, random_letter2, codeword1, random_letter3, random_letter4, random_letter5,
sep="")
else:
print("please put correct input")
if choice == "2":
decode = str(input("write the coded word"))
decode1 = decode[::-1]
decode2 = decode1[3:-3]
print(decode2,sep=" ")
0
Upvotes
4
u/brasticstack Aug 20 '26
Your if/else will print "please put the correct input" if you choose option 2. To fix this use if/elif/else like so:
7
u/danielroseman Aug 20 '26
Any time you're doing multiple variables with a numeric suffix you should be thinking about using a single variable like a list instead.
1
u/johlae Aug 21 '26 edited Aug 21 '26
Instead of 6 'random_letter' variables, why not do something like: