[Tutor] (no subject)

2018-06-01 Thread erich callahana
I’m not sure how to access this window 



Sent from my iPhone___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2018-06-01 Thread Alan Gauld via Tutor
On 31/05/18 07:06, erich callahana wrote:
> I’m not sure how to access this window 
>

Unfortunately this is a text mailing list and the server strips binary
attachments for security reasons. Either send us a link to a web
page or describe what it is you are trying to do.

Include the program name, the OS, and the Python version you
are using.

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

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] guess my number game (reversed)

2018-06-01 Thread chiara pascucci
Hello.

I am very new to learning Python, and I would need some help with a little
game I am trying to write. I am trying to write a game where the user is
asked to think of a number from 1 to a 100, and the computer tries to guess
it. Now, after every guess I would want the programme to ask whether its
guess is right, too low, or too high, and then take another guess based on
the user's input. The programme works fine if the it guesses the number
right on its first try, but when the users inputs "too low" or "too high"
an infinite loop is returned. I thinkI have done something wrong in my
while loop and that my sentry variable is somehow wrong -but I can't seem
to be able to fix it!
Any help or commments would be very appreciated.
Below is the code written so far

Many thanks

Chiara

print("think of a number from 1 to 100")
print("I will try and guess it!")

import random

number = random.randint(1,100)
print(number)

answer = input("is this right, too high, or too low?")

while answer != "right":
if answer == "too high":
number2 = random.randint(1,number)
print(number2)
elif answer == "too low":
number3 = random.randint(number,100)
print(number3)

print("I finally guessed your number. Thank you for playing")


input("\n\nPress enter key to exit")
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] guess my number game (reversed)

2018-06-01 Thread Alan Gauld via Tutor
On 01/06/18 14:00, chiara pascucci wrote:

> the user's input. The programme works fine if the it guesses the number
> right on its first try, but when the users inputs "too low" or "too high"
> an infinite loop is returned. I thinkI have done something wrong in my
> while loop and that my sentry variable is somehow wrong

Nope, it's simpler than that.

You only ask the user for input once, outside the loop.
Move the input() statement inside the loop before the if
statements and all should be well. (You will also need to
initialise answer to some value - an empty string
say - before entering the while loop.)

> print("think of a number from 1 to 100")
> print("I will try and guess it!")
> 
> import random
> 
> number = random.randint(1,100)
> print(number)
> 
> answer = input("is this right, too high, or too low?")
> 
> while answer != "right":
> if answer == "too high":
> number2 = random.randint(1,number)
> print(number2)
> elif answer == "too low":
> number3 = random.randint(number,100)
> print(number3)
> 
> print("I finally guessed your number. Thank you for playing")

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


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] guess my number game (reversed)

2018-06-01 Thread Farooq Karimi Zadeh
Add a new variable named "number of guesses", increase it each time
and break the loop when it reaches, for example 10. This means user
can have 10 guesses max. If they couldn't guess the number, they are
losers!
You also could do the opposite: have number of guesses=10 in the
beginning and decrease it by 1 each time till it reaches zero.

On 01/06/2018, chiara pascucci  wrote:
> Hello.
>
> I am very new to learning Python, and I would need some help with a little
> game I am trying to write. I am trying to write a game where the user is
> asked to think of a number from 1 to a 100, and the computer tries to guess
> it. Now, after every guess I would want the programme to ask whether its
> guess is right, too low, or too high, and then take another guess based on
> the user's input. The programme works fine if the it guesses the number
> right on its first try, but when the users inputs "too low" or "too high"
> an infinite loop is returned. I thinkI have done something wrong in my
> while loop and that my sentry variable is somehow wrong -but I can't seem
> to be able to fix it!
> Any help or commments would be very appreciated.
> Below is the code written so far
>
> Many thanks
>
> Chiara
>
> print("think of a number from 1 to 100")
> print("I will try and guess it!")
>
> import random
>
> number = random.randint(1,100)
> print(number)
>
> answer = input("is this right, too high, or too low?")
>
> while answer != "right":
> if answer == "too high":
> number2 = random.randint(1,number)
> print(number2)
> elif answer == "too low":
> number3 = random.randint(number,100)
> print(number3)
>
> print("I finally guessed your number. Thank you for playing")
>
>
> input("\n\nPress enter key to exit")
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor