Below is my code, I have a few questions. 1. My Validation for my variable Guess
ID: 3857961 • Letter: B
Question
Below is my code, I have a few questions.
1. My Validation for my variable Guess is not working. (if guess < 0 and guess > 100) print enter valid code. Please help.
2. How would I add *hint* that generates within a function? (Example, press 0 to see a hint of the random number)
3. How can I have the hint use only 3 MAX, and the hint comes up randomly?
import random
tries = 0
print('hello, enter your name?')
name = input()
print('Hello', name, 'Enter your number between 1 to 100:')
number = random.randint(1,100)
while tries < 10:
getTries = tries
getTries = str(getTries)
print('Take a guess, ', getTries)
guess = input()
guess = int(guess)
tries = tries + 1
if guess < 0 and guess > 100:
print('Enter a valid input')
if guess < number:
print('You are low')
if guess > number:
print('you are high')
if guess == number:
break
if guess == number:
print('you win, great job')
if guess != number:
print('you lost, sorry. The number was ', number)
Explanation / Answer
import random tries = 0 print('hello, enter your name?') name = input() print('Hello', name, 'Enter your number between 1 to 100:') number = random.randint(1, 100) while tries < 10: getTries = tries getTries = str(getTries) print('Take a guess, ', getTries) guess = input() guess = int(guess) tries = tries + 1 #You used and for the below if condition. Using or helps you to check the number if guess < 0 or guess > 100: print('Enter a valid input') if guess number: print('you are high') if guess == number: break if guess == number: print('you win, great job') if guess != number: print('you lost, sorry. The number was ', number)Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.