0

Secret Code Python (Help pls)

The problem I have is that I do not know how to make a COMPARISON of the letters of the alphabet with the letters that I enter from the word on the keyboard. I know I can do it by other methods, but I want to try this one that I propose here, if in that case you wish. Please can you see my code posted on my profile. Thanks a lot. #I have my code. I try to explain all in comments. # # Incomplete code #Secret code: The objective is to write a word and that the first letter is replaced with the last letter, and so correspondingly, # -> the second with the penultimate letter. # -> the third with the third to last letter ... cont_asc= -1 cont_des= 0 from string import ascii_lowercase print ("The letters of the alphabet are: \n\t",ascii_lowercase) #cap word, number of characters def longitudCadena(w): return len(w) def nombrePropio(w): return w.capitalize() w=input('Input a word: ') print(nombrePropio(w),'have',longitudCadena(w),'characters.') #print ("String length is:", String length (w)) #change variable name i=(longitudCadena(w)) #loop to see corresponding string space. The length is size taken and compared until it is other than 0 to exit the loop. while i != 0: i= i-1 print("'",w[i],"'","Corresponds to the cell ",i," of the chain") #pulled apart print("\nLetter correspondence:\n") for x in (ascii_lowercase): cont_asc= cont_asc +1 cont_des= cont_des -1 x = cont_asc y = cont_des #print (x,y) print ( "First Letters: ",x,"->", ascii_lowercase[x],"\t", "Last Letters: ",y,"->", ascii_lowercase[y]) #print (x, ascii_lowercase[x]) #print (y, ascii_lowercase[y]) #Counts in 25

27th Nov 2020, 9:02 AM
David Romero Vaca
David Romero Vaca - avatar
2 Answers
+ 2
it seems like a lot when you can just make a dictionary with each letter cooresponding to it's logical opposite. alph_code = {'a': 'z', 'b': 'y', ...}
27th Nov 2020, 9:27 AM
Slick
Slick - avatar
+ 1
It's a good idea, because I'm doing it in the worst way jaja Ty for that...
27th Nov 2020, 9:31 AM
David Romero Vaca
David Romero Vaca - avatar