Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
好的,我正在写一个小游戏来练习我的python,因为我正在学习,在过去的一周里我学到了很多东西,但是对于这个特定的游戏我很困惑。
它是一个掷骰子游戏(我知道很无聊)但是,它的实践很好
我想让程序做的是询问用户有多少人在玩,然后取用户输入的整数并根据有多少人在玩骰子
就像我输入 3 一样,它会掷骰子 3 次。
这应该适用于您正在尝试做的事情:
import random try: num_players = input("How many people are playing?") die_rolls = [] for i in range(1,num_players + 1): die_rolls.append(random.randint(1,6)) print die_rolls except: print "Error"