[英]When user input matches up with one bit in list, print something, if not then print something else
I'm very new to python and coding in general.我对python和一般编码很陌生。 currently trying to make a program that asks the user for a code, and if the code matches up with one of the bits in the list then it prints saying the code was accepted and quits the program.当前正在尝试制作一个程序,要求用户输入代码,如果代码与列表中的某个位匹配,则它会打印出代码已被接受并退出程序。 otherwise it says the code is invalid and loops back to the user input.否则它说代码无效并循环回到用户输入。
The issue I have is that it asks the user for the code and regardless of what is inputted it says it is invalid我遇到的问题是它要求用户提供代码,无论输入什么,它都说它无效
codes = ['1234', '5678', '2684', '1243', '3565', '3458', '4589']
truecode = False
while not truecode:
user_input = input('Please input your code')
if user_input is codes:
print('Code accepted, enjoy your voucher')
else:
print('Code is invalid, please try again')
Try in
instead of is
:尝试in
代替is
:
if user_input in codes:
print('Code accepted, enjoy your voucher')
else:
print('Code is invalid, please try again')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.