【发布时间】:2017-08-24 21:27:17
【问题描述】:
import sys
def main():
print("\t\tGame Menu\n")
print("\t\tA - enter your name\n\t\tB - play the game\n\t\tC - quit")
s = input("please enter your choice").upper()
valid_option = ['A','B','C']
while True:
if s in valid_option['A']:#here
n=input("please enter your name")
print("I welcome thee valient night sir", n)
print("\t\tGame Menu\n")
print("\t\tA - enter your name\n\t\tB - play the game\n\t\tC -
quit")
elif s in valid_option['B']:#here
print("the game is starting,")
print("\t\tGame Menu\n")
print("\t\tA - enter your name\n\t\tB - play the game\n\t\tC -
quit")
elif s in valid_option['C']:#and here
print("you have chosen to depart from our company, farewell
traveler")
sys.exit()
main()
当我尝试运行它时,它显示 TypeError: list indices must be integers or slices, not str
请帮忙
【问题讨论】:
-
你认为那行代码应该做什么?
-
你用数字索引列表,正如错误所说。您希望它与“B”做什么?你是说 1 吗?
标签: python