Python dice game
I must create a dice game that generates numbers from 1 to 6. It will then
throw the dice 50 times and it will count the number of odd numbers and
even numbers. I'm using Python.
Here is my code:
import random
# Determine odd and even numbers
throws = 0
even = 0
odd = 0
maxthrows = 50
print "Even : Odd"
while True:
throws += 1
if throws == maxthrows:
break
dice = random.randrange(6)
if dice % 2 == 1:
odd += 1
else:
even += 1
print even, " : ", odd
raw_input("Press enter to exit.")
No comments:
Post a Comment