Sep-03-2018, 03:42 AM
(This post was last modified: Sep-03-2018, 03:43 AM by rafaelssouzza.)
Good night, mates. I need some help
I need to develop an algorithm that generates a number between 1 and 10, asks me to try to guess it and tells me if its too high or too low, and if i get it right is offers me another random until i write "quit".
So far i've done this, but the part where it should offer me a new random number is not working. Also the secure word "quit" doesnt break the loop.
I've tried many combinations, but i just can't fix the mistake.
I need to develop an algorithm that generates a number between 1 and 10, asks me to try to guess it and tells me if its too high or too low, and if i get it right is offers me another random until i write "quit".
So far i've done this, but the part where it should offer me a new random number is not working. Also the secure word "quit" doesnt break the loop.
I've tried many combinations, but i just can't fix the mistake.
import random def startgame(): while b != 'quit': b = 0 a = random.randint (1,10) cont = 0 while True: b = input("Guess a number: ") if b == 'quit': break elif int(b) > a: print("Too high!") cont += 1 elif int(b) < a: print ("Too low!") cont += 1 elif int(b) == a: print ("You got it right!") print ('You needed ',cont,'guesses!') False startgame()