Question: Python: Write a program using the ord function: it should take a character as input and output the corresponding number (between 1 and 26). Your
Python: Write a program using the "ord" function: it should take a character as input and output the corresponding number (between 1 and 26). Your program should only accept capital letters. As error-checking, print invalid if the input is not a capital letter.
#my code. Can't seem to get it to work correctly
# I keep getting hung up when "@" is the input
letter = input() if (len(letter) > 1 or letter != letter.upper()) or letter != letter.isalpha(): print("invalid input") else: print(ord(letter)-ord("A")+1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
