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 评论