i have this little bit problem where after i generate random number to a list of 50 when i input the same number on the list, it does not print "match found". it will always send me "no match found". can you guys explain what is wrong with the code.
import random
mylist=[]
for i in range (50):
x= random.randint(100,999)
mylist.append(x)
print(mylist)
p = input('Enter an integer number: ')
for i in range(len(mylist)):
if p == mylist[i]:
print('Match found at position')
break
else:
print('no match found')
example of output
[836, 569, 378, 788, 847, 584, 404, 159, 362, 271, 151, 100, 702, 414, 867, 213, 194, 553, 946, 930, 777, 143, 143, 879, 724, 752, 431, 416, 944, 509, 752, 211, 713, 951, 882, 836, 710, 998, 447, 892, 720, 210, 364, 768, 603, 456, 540, 727, 346, 153]
Enter an integer number: 836
no match found
>>>
i just started learning coding so if u guys can explain it i would be happy to understand for future reference :)
Aucun commentaire:
Enregistrer un commentaire