import re from random import randint def rand_list(): ans = list() for i in rang
ID: 3889566 • Letter: I
Question
import re
from random import randint
def rand_list():
ans = list()
for i in range(6):
ans.append(randint(1, 59))
# print(ans)
return ans
def comparelist(x, y):
z = list(set(x).union(set(y)))
if len(z) is len(x):
return True
return False
l = input('Enter six numbers for the lottery:')
l = l.split()
try:
for a in range(0, len(l)):
l[a] = int(l[a])
except:
print ('Enter integer values')
l.sort()
l = list(set(l))
if len(l) != 6:
print ('Invalid input')
exit()
for a in range(6):
if l[a] < 1 and l[a] > 59:
print ('Invalid input')
exit()
for i in range(1, 9001):
rlist1 = randlist()
rlist1.sort()
if comparelist(l, rlist1):
cost = (i - 1) * 3 + 1
print ('On week ' + i + ', numbers are:' + ','.join(rlist1))
print ('You are a MILLION DOLLAR winner!!')
print ('Your total return is $' + str(1000000 - cost))
print ('Total amount spent is $' + str(cost))
exit()
rlist2 = randlist()
rlist2.sort()
if comparelist(l, rlist2):
cost = (i - 1) * 3 + 2
print ('On week ' + i + ', numbers are:' + ','.join(rlist2))
print ('You are a MILLION DOLLAR winner!!')
print ('Your total return is $' + str(1000000 - cost))
print ('Total amount spent is $' + str(cost))
exit()
rlist3 = randlist()
rlist3.sort()
if comparelist(l, rlist3):
cost = (i - 1) * 3 + 3
print ('On week ' + i + ', numbers are:' + ','.join(rlist3))
print ('You are a MILLION DOLLAR winner!!')
print ('Your total return is $' + str(1000000 - cost))
print ('Total amount spent is $' + str(cost))
exit()
cost = 9000 * 3
print ('Total amount spent is $' + str(cost))
The error is :
plz fix the error.
Enter six numbers for the lottery: 7 14 17 38 44 50 Traceback (most recent call last): Pile "main.py", line 19, in I = input ('Enter six numbers for the lottery') File "",line 1 7 14 17 38 44 50 SyntaxError: invalid syntax xited with non-zero statusExplanation / Answer
The error in the code is that after the user gives input and you are splitting the input to individual items but not converting that item to integer and instead of storing it as a string. So this might trigger an error. so change the this line
l = l.split()
l = [int(x) for x in l.split()]
And i also could not find the implementation of randlist(). so implement this function to not get the further errors.
**Comment further for any queries
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.