Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何给三个字母单独的任务_Python 3.x - Fatal编程技术网

Python 3.x 如何给三个字母单独的任务

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'

我希望用户能够输入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'):
    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')