如何对列表中的每个元素执行某些操作?

时间:2016-11-06 16:04:31

标签: python

我正在制作一个宾果游戏,当按下输入时调用一个数字。这样做直到玩家的宾果卡空了。

我无法得到它,所以它调用数字列表中的第一个数字,然后继续调用第二个数字,然后调整第三个数字,依此类推,而不为99个数字中的每一个编写脚本。

我想要做的是让程序找到nums的第一个元素,然后让程序打印字符串,如果字符串在player_1列表中,则从中删除字符串player_1继续执行该过程,直到程序完成所有字符串或player_1列表中没有字符串。

这是我的代码:

import random

def player_1_card():
   print(player_1[1:4])
   print(player_1[5:8])
   print(player_1[9:12])
   print(player_1[13:16])
return

nums = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99']

random.shuffle(nums)
player_1 = random.sample((nums), 16)

while len(player_1) != 0:
        input("Press <enter> to call a number")
        for i in nums:
            print("Your current bingo card:")
            player_1_card()
            print("Number called is", # )
            input("Press <enter> to call a number")
            if nums(#) in player_1:
                nums.remove(#)

我已经放置了哈希,我需要一些代码帮助。

我使用的是Python 3.5.2。

0 个答案:

没有答案