number of loops
Bob Gailer
bgailer at gmail.com
Thu Mar 15 11:25:37 EDT 2018
On Mar 15, 2018 9:30 AM, <michealmancini at gmail.com> wrote:
>
> I would like to have this offer 6 guesses, but instead it gives one guess
and prints the if statement/output 6 times....any ideas where I went wrong?
I suggest you conduct a walk-through. That means pointing using a pencil or
a mouse pointer at each statement and noticing what it does. pay attention
to what happens when the loop repeats.
This will do more for you than if I just tell you the answer.
>
> import random
>
> number_of_guesses = 0
>
> print ('Hello! what is your name?')
> my_name=input()
> print (my_name + " " + 'sounds like the name of my next opponent')
> print ('Shall we play?')
>
> yes_or_no = input()
>
> if yes_or_no == 'yes':
> print ('ok! guess my number')
> else:
> print ('log off and go home')
>
> my_number=random.randint(1,100)
>
> your_guess=input()
> your_guess=int(your_guess)
>
> for number in range(6):
> if your_guess > my_number:
> print ('nope, too high')
> if your_guess < my_number:
> print ('nope, too low')
> if your_guess == my_number:
> break
>
> if your_guess == my_number:
> number_of_guesses=str(number_of_guesses)
> print ('good job, you guessed correctly')
> else:
> print('nope, you lose')
>
> --
> https://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list