+ 3

Please tell me why this code is not outputting the desired output?It always prints z.

x=input() y=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"] m=['Z', 'Y', 'X', 'W', 'V', 'U', 'T', 'S', 'R', 'Q', 'P', 'O', 'N', 'M', 'L', 'K', 'J', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A'] if y[1].lower or y[1] in x: print(m[1].lower()) elif y[0].lower or y[0] in x: print(m[0].lower())

9th Sep 2021, 2:16 AM
Vaibhav Tiwari
7 Respuestas
+ 6
Vaibhav Tiwari , here is a try with some comments. it uses everything in lower case letter. the 2 alphabets do not need to be lists, can also be strings. it uses a for loop, that iterates over the input string, check if character is in alphabet, get its index, and pick the character at then same index. then add it to the string. there are various ways to do this task. most of them may be more elegant, much shorter or more efficient. don't care about at this time. it is important that you understand the steps. later on you can make more version. happy coding! txt = input().lower() alph_asc = "abcdefghijklmnopqrstuvwxyz " # alphabet ascending order alph_rev = "zyxwvutsrqponmlkjihgfedcba " # alphabet reverse order new_str = "" for char in txt: # iterate through input if char in alph_asc: # make sure that char exists ind = alph_asc.index(char) # get index position of char new_str += alph_rev[ind] # use char at the same index print(new_str)
9th Sep 2021, 7:08 PM
Lothar
Lothar - avatar
+ 8
Vaibhav Tiwari , as you can see, people have started guessing due to lack of a description. please give a complete and clear description what your code should achieve. add also an input sample and the expected output. thanks!
9th Sep 2021, 6:19 AM
Lothar
Lothar - avatar
+ 1
Oh yes I am trying to solve secret message challenge
9th Sep 2021, 11:02 AM
Vaibhav Tiwari
+ 1
Thanks but how to add space between two letters
10th Sep 2021, 3:42 AM
Vaibhav Tiwari
0
In the code coach menu
9th Sep 2021, 11:03 AM
Vaibhav Tiwari
9th Sep 2021, 11:04 AM
Vaibhav Tiwari
0
if the code is suppossed to print the word with corresponding values from the other list then it should run as shown below.................................. x=input() y=[" ","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"] m=[' ','Z', 'Y', 'X', 'W', 'V', 'U', 'T', 'S', 'R', 'Q', 'P', 'O', 'N', 'M', 'L', 'K', 'J', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A'] x=x.upper() lst=[] for i in x: if i in y: z=y.index(i) lst.append(m[z].lower()) print("".join(lst))
10th Sep 2021, 10:55 PM
Otieno Sudi Abdalla
Otieno Sudi Abdalla - avatar