mardi 10 janvier 2023

Trying to iterate through a list with a for loop, although I receive a 'list' object is not callable error [closed]

I am creating a random linear search program. After adding 1000 random numbers between 0 and 3000 to a list, I am not able to iterate through the list with a for loop as I receive an error called 'list' object is not callable. Here is my code:

import random

randomnumberlist=[]

randomnumbers=random.randint(0,3001)

count=0

while count<1000:
    randomnumbers=random.randint(0,3001)
    randomnumberlist.append(randomnumbers)
    count+=1

userinput=int(input("Choose number between 1 and 3000"))



for i in randomnumberlist():
    if i==userinput:
        print("Your number has been found")
    else:
        print("Your number is not in the list")``

I expected this to work by the for loop just iterating through the for loop and if it finds the number it will stop and output 'Your number has been found' or if the number is not found to output 'Your number is not in the list'




Aucun commentaire:

Enregistrer un commentaire