The given question is:
"You can roll a dice up to six times. You can stop when you want and you get the dollar amount shown on that roll. For example, Max rolls a 2, 4, 3, 6, and decides to stop. He wins $6. Hans rolls a 3, 2, 4, 5 and stops. David wins $5. Let’s assume you keep rolling until you get a 4 or greater, then you stop. How much would you typically win on each play? What happens if the maximum possible rolls are reduced from 6 to 4?"
The code I've written is:
import random
run = 0
total_runs = 0
# x = [1,2,3,4,5,6]
y = 0
#k=0
while run < 50:
run = run + 1
roll_count = 1
average = roll_count / run
while roll_count < 4:
a = random.randint(1, 6)
if a < 4:
roll_count = roll_count + 1
elif a >= 4:
y = a
break
print("Trial Run:", run)
print("Times rolled:", roll_count)
print("Your score:", y)
print("Your prize:", y)
#if y >= 4:
#break
print ("Average rolls:",average)
The output I get is:
Trial Run: 1
Times rolled: 1
Your score: 4
Your prize: 4
Trial Run: 2
Times rolled: 2
Your score: 6
Your prize: 6
Trial Run: 3
Times rolled: 4
Your score: 6
Your prize: 6
Trial Run: 4
Times rolled: 1
Your score: 4
Your prize: 4
Trial Run: 5
Times rolled: 1
Your score: 5
Your prize: 5
.
.
(continued)
.
.
Trial Run: 49
Times rolled: 1
Your score: 4
Your prize: 4
Trial Run: 50
Times rolled: 1
Your score: 5
Your prize: 5
Average rolls: 0.02
What I want to do:
I want to find average (roll_count/run) at the end of the code i.e after 50 runs.