Hi, I have this program where you enter lotto numbers and it tells you if you entered all numbers from 1 to 99 and the file input ends with 0.
Here is the main program: DEMO.py
# 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")
And here is the file input: LottoNumbers.txt
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
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 0
But when I execute it in the command line I get this error:
What am I doing wrong. Doesn’t each line in LottoNumbers.txt get inputted and it is turned into a string by the function input()? Please help.
Thanks.
By the way, I tried making each line in LottoNumbers.txt into strings, so
" 1 2 3 4 5 6 7 8 9 10"
…
And that worked but the textbook didn’t have to do that.