This is the code, but I see no mistake. It is supposed to be a simple guessing game.
import random
a=random. randint(1, 10)
b=random. randint(11, 20)
guess_count=0
print('Hello, pick a number from '+str(a)+' '+'to '+str(b)+'.')
number=int(input())
guess=random. randint(a, b)
while number < guess:
print('Number too low. Guess again: ')
number=int(input())
guess_count+=1
while number > guess:
print('Number too high. Guess again: ')
number=int(input())
guess_count+=1
if number == guess:
print('Nice, you guessed right!')
print('It took you '+str(guess_count)+' attempts.')
I tried some methods my teacher showed me but none of them worked. I expect it to go on forever until you don’t guess the right number.
>Solution :
This maybe what you intend:
import random
a=random. randint(1, 10)
b=random. randint(11, 20)
guess_count=0
print('Ahoj, zadaj cislo od '+str(a)+' '+'do '+str(b)+'.')
number=int(input('Guess a number: '))
guess=random. randint(a, b)
while number < guess or number > guess:
guess_count+=1
if number < guess:
print('Number too low. Guess again: ')
else:
print('Number too high. Guess again: ')
number=int(input('Guess a number: '))
print(f"Nice, you guessed right! It took you {guess_count} attempts.")