如何给三个字母单独的任务

时间:2014-10-10 21:00:22

标签: python-3.x

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)

我希望用户能够输入E,N或H,然后用它来打印他们之后选择的内容。

1 个答案:

答案 0 :(得分:1)

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')

REPL:http://repl.it/1J4/1