# A simple project for many dicerolling game counting double 6s but difficulty on iteration

The problem is simple play a dice game rolling a pair of dice, count the number of rolls per “round” it takes to get double 6s, then ask the player to hit enter or q (or any other key) an enter starts a new round and a Q(or any other key) ends the game and simply gives an average for the rounds. They key press sections are giving me a ton of trouble unsure how to go about solving it but the dice game is very basic so im sure there is a technique im not looking at.

import random

averages =
def dicegame():
s = 0
t = 0
r = 0
while s < 12:
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
t = t + 1
s = dice1+dice2
if s == 12:
r += 1
print (‘Round #’, r, ’ took’, t, ‘rolls to get double sixes.’)
averages.append(t)
t = 0
avg = sum(averages)/len(averages)
return avg

I just need to figure out how to start the process over on a enter key, or stop it on any other keypress and only have it return the average on those alternative keypresses. Any suggestions would be much appreciated.

If you want to repeat something until something happens… that’s a loop

I there is a lot of info on how to terminate a loop via key press, but I need basically two different inputs resulting in 2 different patterns. An enter key loops the function back, and any other keypress which terminates the function and returns the average.

The key press wouldn’t do it, you’d read a key and then in your loop you’d test which key it was

So there’s an action, read the key, you’d need to decide when that should happen and put that in the location where program control would be at that time, and a condition, which you’d put in the loop header.