Question
I am getting error NameError: name 'guessCount' is not defined in python. Can you please reeview my code below. #Python program that prompts user to
I am getting error "NameError: name 'guessCount' is not defined" in python. Can you please reeview my code below.
#Python program that prompts user to enter a guess number and #continues until user enters the correct guess #Part-I #guess1.py import random def main(): #set number of guesses =0 guessCount=0 randomNumber = random.randint(1, 10) print('Guessing Number Game') print('Guess a number in a range of 1 to 10') #set run is True run=True
#run the loop until user guess is correct while run: guessCount=guessCount+1 guess = int(input('Enter your guess number : ')) #check if guess is low if guess < randomNumber: print('Your guess is too low.') #check if guess is high elif guess > randomNumber: print('Your guess is too high.') #guess is random number elif guess == randomNumber: run=False print('Congratualtions!')
print('# of guesses taken are ',guessCount) #calling main method main()
#Python program that prompts user to enter a guess number and #continues until user enters the correct guess upto four guesses. #Part-II #guess2.py import random def main(): #set number of guesses =0 guessCount=0 randomNumber = random.randint(1, 10) print('Guessing Number Game') print('Guess a number in a range of 1 to 10') #set run is True run=True
#run the loop until user guess is correct while guessCount < 4 and run: guessCount=guessCount+1 guess = int(input('Enter your guess number : ')) #check if guess is low if guess < randomNumber: print('Your guess is too low.') #check if guess is high elif guess > randomNumber: print('Your guess is too high.') #guess is random number elif guess == randomNumber: run=False print('Congratualtions! You guessed it right..')
if guessCount==4 and guess != randomNumber: print('Max number of guesses are over.')
if guess != randomNumber: print('Better luck next time.Try again') #calling main method 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