Python 3.x 如何给三个字母单独的任务
我希望用户能够输入E、N或H,然后打印他们选择的内容Python 3.x 如何给三个字母单独的任务,python-3.x,Python 3.x,我希望用户能够输入E、N或H,然后打印他们选择的内容 import random print('please enter one of three letters\n E for easy\n N for normal\n H for hard') difficulty = input() if input().upper().startswith('E'): print('E was selected') elif input().upper().startswith('N'
import random
print('please enter one of three letters\n E for easy\n N for normal\n H for hard')
difficulty = input()
if input().upper().startswith('E'):
print('E was selected')
elif input().upper().startswith('N'):
print('N was selected')
elif input().upper().startswith('H'):
print('H was selected')
else:
print('please enter E,N or H)
回复:+1。好处:您通过执行
难度.upper()
而不是输入().upper()
来识别问题。坏消息:在Python 3中,原始输入()被重命名为input()
。丑八怪:今天是星期五,我们在StackOverflow。啊,很有趣。非常感谢。不太熟悉3.x
difficulty = input('please enter one of three letters\n E for easy\n N for normal\n H for hard')
if (difficulty.upper() == 'E'):
# Do "E" things
print('E was selected')
elif (difficulty.upper() == 'N'):
# Do "N" things
print('N was selected')
elif (difficulty.upper() == 'H'):
# Do "H" things
print('H was selected')
else:
print('please enter E,N or H')