Python adding players to a game
Okay I'm writing a little game to practice my python since I'm learning, I've learned开发者_如何学编程 quite a bit over the past week, but with this certain game I'm puzzled.
its a dice rolling game (boring I know) but, its good hands on practice
What I want the program to do, is ask the user how many people are playing, then take the integer that the user inputs and roll the dice accordingly to how many people are playing
like if I input 3 it rolls the dice 3 times.
This should work for what you are trying to do:
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"
精彩评论