JavaScript
x
12
12
1
number = int(input("please choose your number: "))
2
3
while number > number_to_guess:
4
number = int(input("Your guess is wrong it was bigger then the generated number, try again: "))
5
while number < number_to_guess :
6
number = int(input("Your guess was wrong it was smaller then the generated number, try again: "))
7
8
if number == number_to_guess:
9
print("Congrats you won")
10
restart = input("Do you want to play again? if yes type y, if not you can close the window n")
11
12
I’m trying to create a loop and give clues of the number the user has to guess I first tried if statements and it of course didn’t loop and I tried multiple things this was the best I could come up with but it didn’t exactly work it would keep telling me for example: it was smaller but when it became bigger it just stopped and the program didn’t send anything but if I got the number correctly it will say congrats, and also I wanted to make it restart from the beginning after the user wins and type y but I have absolutely no idea of how to do that
Advertisement
Answer
Try in this order
JavaScript
1
13
13
1
number = int(input("please choose your number: "))
2
number_to_guess = 5
3
while number != number_to_guess:
4
if number > number_to_guess:
5
number = int(input("Your guess is wrong it was bigger then the generated number, try again: "))
6
continue
7
if number < number_to_guess :
8
number = int(input("Your guess was wrong it was smaller then the generated number, try again: "))
9
continue
10
print("Congrats you won")
11
restart = input("Do you want to play again? if yes type y, if not you can close the window n")
12
13