编辑:
import random # needed to generate random numbers
def roll_until_doubles():
die_one = random.randrange(1, 7)
die_two = random.randrange(1, 7)
counter = 0
while die_one != die_two:
die_one = random.randrange(1, 7)
die_two = random.randrange(1, 7)
counter+=1
return counter
def main():
counter = roll_until_doubles()
number_of_games = int(input("How many games would you like to play? "))
for i in range(number_of_games):
roll_until_doubles()
print "Congratulations!"
print "It took you " + str(counter) + " many rolls to roll doubles!"
main()
谢谢!它不再崩溃了。但是,我仍然在努力弄清楚如何打印骰子的价值。输出应该是例如:
dice 1 = 5 and dice 2 = 6
dice 1 = 4 and dice 2 = 8
Congratulations!
It took you 2 rolls to roll doubles!
但我得到了这个:
Congratulations!
It took you [x] rolls to roll doubles!
如何打印骰子值?