[英]Comparison operator in While Loop with Tuple() or List[] Python 3
tup=(100,200,300,400,500)
userinput=0
while userinput != tup:
userinput=int(input("Try again"))
x=userinput
所以這是一個小問題,我想從用戶那里接受輸入,直到用戶沒有輸入與tup變量相同的值。 並且一旦用戶添加了其中一個與tup變量相同的值,那么我想將該值添加/移動到x變量。
使用“ in”運算符。
tup=(100, 200, 300, 400, 500)
usrInput = 0
while usrInput not in tup:
usrInput = int(input("Please enter a number: "))
該程序將繼續詢問用戶一個數字,直到他們輸入元組中的一個為止。
用戶的int不能等於整個元組,因此您應該考慮如何根據元組中的值檢查輸入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.