Python 3.1中的无限循环问题

时间:2018-06-01 16:10:24

标签: python loops infinite

我正在使用Python 3.1创建一个旅行社游戏。我的while循环出错了。它将不断重复print()响应。我知道这是因为这是真的,只要这是对人们的回应,但我不知道如何解决它。

people = int(input("Will you be travelling by yourself (1), or as a group of 
two (2)?: "))
while people: 
    if people == 1:
        print("\nAh, a holiday for one! How adventurous.")
    elif people == 2:
        print("\nOoh, bringing a friend! Sounds like fun!")
    else:
        print("\nPlease enter either 1 or 2 to determine the number of 
        travellers.")
        people = int(input("Will you be travelling by yourself (1), or as a 
        group of two (2)?: "))

1 个答案:

答案 0 :(得分:0)

关于你问题的python版本没有任何问题。问题是,循环将无限运行,因为没有条件退出循环。所以在print语句后插入{{1关键字如下。

break