Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

b. Will there be one assigned leader?

Answered: 1 week ago