number of loops
michealmancini at gmail.com
michealmancini at gmail.com
Thu Mar 15 09:28:36 EDT 2018
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?
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')
More information about the Python-list
mailing list