[Tutor] Dice game problems

Alan Gauld alan.gauld at yahoo.co.uk
Thu Mar 19 20:16:28 EDT 2020


On 19/03/2020 19:43, Rodrigo Camacho wrote:

>  The script I proposed was the following:

Please post the code in plain text. The email system has stripped the
spacing out of the code below making it impossible to debug.

Also please include the full error messages - they contain a lot of
information, your summary tells us very little.


> 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.

We need the whole message, not just a summary.
And how did you manage to get two errors so far apart?
Usually python stops at the first error.


> 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.

You can use either loop, for is usually more convenient and considered
better Python style for processing collections. But for 'infinite' loops
while is preferred.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list