我把我所有的输入放进一个文件,然后进入终端运行一个程序,从一个文件中获取输入,但是我得到了一个语法错误。我哪里出错了?谢谢。你知道吗
这是主程序。你知道吗
# Create a list of 99 Boolean elements with value False
isCovered = 99 * [False]
endOfInput = False
while not endOfInput:
# Read numbers as a string from the console
s = input("Enter a line of numbers separated by spaces: ")
items = s.split() # Extract items from the string
lst = [eval(x) for x in items] # Convert items to numbers
for number in lst:
if number == 0:
endOfInput = True
else:
# Mark its corresponding element covered
isCovered[number - 1] = True
# Check whether all numbers (1 to 99) are covered
allCovered = True # Assume all covered initially
for i in range(99):
if not isCovered[i]:
allCovered = False # Find one number not covered
break
# Display result
if allCovered:
print("The tickets cover all numbers")
else:
print("The tickets don't cover all numbers")
以下是输入文件:
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
91 92 93 94 95 96 97 98 99 0
在python3中,代码不显示错误。错误可能在于使用两个版本中不同的input命令(如果使用python2,请尝试使用raw\u input()而不是input())
相关问题 更多 >
编程相关推荐