Hi everyone,
I need help writing a python condition. I cannot use loops (while conditions), and must stick to else/if/elif conditions for it.
It's a guessing game - I need to allow the user to have 4 attempts, and if they don't guess the number after 4 attempts it tells them "You're out of guesses! The number was XX"
I'm having trouble figuring out how to only allow the user to have 4 guesses and then printing the response above. Any help is appreciated
I need help writing a python condition. I cannot use loops (while conditions), and must stick to else/if/elif conditions for it.
It's a guessing game - I need to allow the user to have 4 attempts, and if they don't guess the number after 4 attempts it tells them "You're out of guesses! The number was XX"
I'm having trouble figuring out how to only allow the user to have 4 guesses and then printing the response above. Any help is appreciated
import random import math winning_number = math.floor(20*random.random()) + 1 print("number_chosen = " , winning_number) guesses_remaining = 4 i = 1 print("Guess a number between 1 and 20: ") guess = float(input()) if (guess == winning_number) : print("You win! The number is" , winning_number) else: if (guess < winning_number) : print("That's too low! Try again!") guess = float(input()) if (guess > winning_number) : print("That's too high! Try again!") guess = float(input()) if (guess == winning_number) : print("You win! The number is" , winning_number) else: if (guess < winning_number) : print("That's too low! Try again!") guess = float(input()) if (guess > winning_number) : print("That's too high! Try again!") guess = float(input()) if (guess == winning_number) : print("You win! The number is" , winning_number) else: if (guess < winning_number) : print("That's too low! Try again!") guess = float(input()) if (guess > winning_number) : print("That's too high! Try again!") guess = float(input()) if (guess == winning_number) : print("You win! The number is" , winning_number) if (guesses_remaining != winning_number) : print("You are out of guesses, you lose! The number was", winning_number)