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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!