+ 1

If statement not working

Hi ppl, I have this exercise: Write a program that takes a character as input (a string of length 1), which you should assume is an upper-case character; the output should be the next character in the alphabet. If the input is 'Z', your output should be 'A'. I need to use only the if funktion. here my code: string = input() if ord(string) == 90: print('A') if ord(string) <= 65: if ord(string) >= 89: print(chr(ord(string) + 1)) print('Input not a capital letter') If I input an Z it works and it gives me an 'A'. If I input any other letter it jumps to the last print line. Why? thx

17th Sep 2017, 12:50 AM
TheMurbain
TheMurbain - avatar
4 Antworten
+ 5
if ord(string) <= 65: //means max value of ord(string) will be 65. if ord(string) >=89: // means that ord(string) needs to have a 'minimum' value of 89. so this line of your code doesn't make sense ;)
17th Sep 2017, 1:25 AM
OUMAS Abdellah
OUMAS Abdellah - avatar
+ 5
lol. sometimes i get soo confused and end up using randome comment codes my bad xD
17th Sep 2017, 1:38 AM
OUMAS Abdellah
OUMAS Abdellah - avatar
+ 1
Python code comment is # not //@ OUMAS
17th Sep 2017, 1:35 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
# is only used in PHP, Python and Ruby as of Sololearn-teaching languages
17th Sep 2017, 1:41 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar