Question
Need help with Project 5-2: Guessing Game (Debug) - Current answer in system isn't helping me. My count is off by one, and I cannot
Need help with Project 5-2: Guessing Game (Debug) - Current answer in system isn't helping me. My count is off by one, and I cannot find where the issue is. If the guess in in 7, my return say 6.
#!/usr/bin/env python3
import random count = 0 number = -1
def display_title(): print("Guess the number!") print()
def get_limit(): limit = int(input("Enter the upper limit for the range of numbers: ")) return limit
def play_game(limit): global number, count count = 0 if number == -1: number = random.randint(1, limit) print("I'm thinking of a number from 1 to " + str(limit) + " ") while True: guess = int(input("Your guess: ")) if guess < number: print("Too low.") count += 1 elif guess > number: print("Too high.") count += 1 elif guess == number: print("You guessed it in " + str(count) + " tries. ") return
def main(): display_title() again = "y" while again.lower() == "y": limit = get_limit() play_game(limit) again = input("Play again? (y/n): ") print() print("Bye!")
# if started as the main module, call the main function if __name__ == "__main__": main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started