[Tutor] Dice game problems
Rodrigo Camacho
roch_camo89 at hotmail.com
Thu Mar 19 15:43:18 EDT 2020
To whom it may concern:
I´m a newcomer in PHYTON programing so as you may have experienced, one of the first excersises that beginners are recommended to do (Lantangen P. Python Scripting for Computational Science) is to simulate a dice rolling game and calculate the probability of getting the number 6 after a certain amout of rolls. My idea was, instead of doing it by testing diffrent amount of rolls, use an infinite loop to roll the dice n number of times and when a 6 is obtained, use a counter to register it. Parelly, the probability is calculated as p=n/t, where t is a second counter that registers the amount of rolls that had to be made in order to obtain the correspondent 6´s.
The script I proposed was the following:
import random
n=float(input(“Introduce the number 3 to start the program”))
r=random.randint(1,6)---------------------------------Indentation error
t=0
s=0
p=0
P=0
while n==3:
t+=1
print()
print(r)
print()
if r==6:
s+=1
p=s/t
P=round(P,3)
elif P==0.306:-----------------------------Syntax problem
break
print(“The number of times the dice had to be rolled to obtain a probability value of 0.306 is ”+str(t)+)
Two main erros were obtained: Syntax error and indentation.
I´ve been trying to find information about how to correct the mentioned problems. However, the solutions proposed haven´t worked for me.
I also have tried to separate the script by using functions but I still get the same errors.
Most of the tutorials I found in sources like YOUTUBE, use a FOR loop. However, for learning purposes, I insisted in using a WHILE loop.
Thanks a lot for your help.
Arthur C.
More information about the Tutor
mailing list