Reputation: 339
I have a scenario. I have a list with ID like result = ['003234568', '000000001', '123456789'].
I want to ask user to input ID and loop until ID is unique. I try this one but doesn't get expected output.
result = ['003234568', '000000001', '123456789'].
playersID = int(input ("Enter ID of the player: "))
while playersID in result:
print ("players id already exist, please enter new one")
playersID = int(input ("Enter ID of the player: "))
I don't want to use any other libraries.
Upvotes: 0
Views: 34
Reputation: 5613
Your result
is a list of strings and you are taking input as integer, that's why playersID
is never in result
. You need to change the input lines to the following:
Change
playersID = int(input("Enter ID of the player: "))
To
playersID = input("Enter ID of the player: ")
Upvotes: 1