[英]python: how to check the integer input by user match the item in the list of not?
我有一個場景。 我有一個ID為result = ['003234568','000000001','123456789']的列表。
我想問用戶輸入ID並循環直到ID唯一。 我嘗試了這一步,但沒有得到預期的輸出。
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: "))
我不想使用任何其他庫。
您的result
是一個字符串列表,並且您將輸入作為整數,這就是為什么playersID
永遠不會返回result
。 您需要將輸入行更改為以下內容:
更改
playersID = int(input("Enter ID of the player: "))
至
playersID = input("Enter ID of the player: ")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.