Py学习  »  Python

Python:对列表中的输入进行验证

boonie • 6 年前 • 2587 次点击  

在这个程序中,q的验证不起作用。除integer之外的任何其他值都会引发相同的消息“Enter integer values only”。即使输入为“q”,也会发生这种情况。 为什么会这样?解决这个问题的办法是什么?

my_list = []

print("Enter q once done")

while True:
    try:
        my_list.append(int(input()))
    except:
        if input == 'q':
            break
        else:
            print("Give integer values only")
            continue

print(my_list)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/56243
文章 [ 2 ]  |  最新文章 6 年前