拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 python-如何回圈串列,直到串列中的所有项目都与用户输入匹配,然后使用宾果游戏的宾果讯息停止回圈

python-如何回圈串列,直到串列中的所有项目都与用户输入匹配,然后使用宾果游戏的宾果讯息停止回圈

白鹭 - 2022-02-13 2119 0 0

my_list 当匹配所有数字时,项目应与用户输入匹配,讯息应显示宾果游戏并应停止回圈

print('...............Welcome to BINGO.................')

my_list = ["15", "22", "35", "48", "80", "55", "12", "36", "45", "26"]
    
i = str(input("press ENTER to play BiNgO!"))
     
for i in range(10):
    number_input = input("enter a number between 1 to 80")

    if number_input in my_list:           
        my_list.remove(number_input)
        print("hurray! this number is matched")
    else:
        print("oops! not matched")

uj5u.com热心网友回复:

试试这个:

my_list = ["15", "22", "35", "48", "80", "55", "12", "36", "45", "26"]

i = str(input("press ENTER to play BiNgO!"))

for i in range(10):

   number_input = input("enter a number between 1 to 80")

   if number_input in my_list:
       my_list.remove(number_input)
       print("hurray! this number is matched")
       break

   else:
       print("oops! not matched")

uj5u.com热心网友回复:

while当我们不知道要进行的迭代次数时,我们需要使用回圈。

while当回圈应终止my_list是空的。

所以代码应该是:

print('...............Welcome to BINGO.................')

my_list = ["15", "22", "35", "48", "80", "55", "12", "36", "45", "26"]
    
i = input("press ENTER to play BiNgO!")
     
while my_list != []:
    number_input = input("enter a number between 1 to 80")

    if number_input in my_list:           
        my_list.remove(number_input)
        print("hurray! this number is matched")
    else:
        print("oops! not matched")
标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *