Simulate rolling dice in Python?

user2027690 picture user2027690 · Jan 31, 2013 · Viewed 15.9k times · Source

first time writing here.. I am writing a "dice rolling" program in python but I am stuck because can't make it to generate each time a random number

this is what i have so far

import random

computer= 0 #Computer Score
player= 0 #Player Score

print("COP 1000 ")
print("Let's play a game of Chicken!")

print("Your score so far is", player)

r= random.randint(1,8)

print("Roll or Quit(r or q)")

now each time that I enter r it will generate the same number over and over again. I just want to change it each time.

I would like it to change the number each time please help I asked my professor but this is what he told me.. "I guess you have to figure out" I mean i wish i could and i have gone through my notes over and over again but i don't have anything on how to do it :-/


by the way this is how it show me the program

COP 1000
Let's play a game of Chicken!
Your score so far is 0
Roll or Quit(r or q)r

1

r

1

r

1

r

1

I would like to post an image but it won't let me


I just want to say THANK YOU to everyone that respond to my question! every single one of your answer was helpful! **thanks to you guys I will have my project done on time! THANK YOU

Answer

Nix picture Nix · Jan 31, 2013

Not sure what type of dice has 8 numbers, I used 6.

One way to do it is to use shuffle.

import random
dice = [1,2,3,4,5,6]
random.shuffle(dice)
print(dice[0])

Each time and it would randomly shuffle the list and take the first one.