High/low game in Pycharm
Question:
import random
name = input("Enter your name:")
print("Hello and welcome to the game", name + "!")
lower_num = int(input("Enter the Lower bound:"))
print()
higher_num = int(input("Enter the Higher bound:"))
print()
user_num = random.randint(0, 10)
guess_num = int(input())
while True:
if user_num == guess_num:
print('n"You guessed correctly!"n')
break
elif user_num > guess_num:
print('n"Wrong, is too low."n')
elif user_num < guess_num:
print('n"Number is too high."n')
This is what I have so far but is not working for me in Python.
Answers:
You have to write the input inside the loop. If the person don’t guess right num then the loop continue. For this, you need to write ‘continue’ under the elif. Then he can guess again.
while True:
guess_num = int(input("Guess a number now:"))
if user_num == guess_num:
print('n"You guessed correctly!"n')
break
elif user_num > guess_num:
print('n"Wrong, is too low."n')
continue
elif user_num < guess_num:
print('n"Number is too high."n')
continue
And what is the lower bound and higher bound for?
import random
name = input("Enter your name:")
print("Hello and welcome to the game", name + "!")
lower_num = int(input("Enter the Lower bound:"))
print()
higher_num = int(input("Enter the Higher bound:"))
print()
user_num = random.randint(0, 10)
guess_num = int(input())
while True:
if user_num == guess_num:
print('n"You guessed correctly!"n')
break
elif user_num > guess_num:
print('n"Wrong, is too low."n')
elif user_num < guess_num:
print('n"Number is too high."n')
This is what I have so far but is not working for me in Python.
You have to write the input inside the loop. If the person don’t guess right num then the loop continue. For this, you need to write ‘continue’ under the elif. Then he can guess again.
while True:
guess_num = int(input("Guess a number now:"))
if user_num == guess_num:
print('n"You guessed correctly!"n')
break
elif user_num > guess_num:
print('n"Wrong, is too low."n')
continue
elif user_num < guess_num:
print('n"Number is too high."n')
continue
And what is the lower bound and higher bound for?