Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

When you are complete, the file should be able to run through the Python Interpr

ID: 3907072 • Letter: W

Question

When you are complete, the file should be able to run through the Python Interpreter with no error messages, producing the correct output Write a simple number guessing game. The game will generate a random number between 1 and 10, the prompt the user to input a number between 1 and 10. Keep prompting them until they get the number correct, counting the number of guesses until they get it correct. When they finally get it, give them a congratulatory message along with how many guesses it took them. Make sure your grammar is correct, just in case they get it in a single guess. Now we will create a modified version of the game you just had the user play. Now we will limit the number of guesses they can make to four (4). If they get it right, then display the messages from the original game. If not, then give them a game over message and encourage them to play again. Examples:

Explanation / Answer

#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()


Sample Output:

Guessing Number Game
Guess a number in a range of 1 to 10
Enter your guess number : 5
Your guess is too high.
Enter your guess number : 4
Your guess is too high.
Enter your guess number : 2
Congratualtions!
# of guesses taken are 3

-------------------------------------------------------------------------------------------


#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()


Sample Output:
Guessing Number Game
Guess a number in a range of 1 to 10
Enter your guess number : 5
Your guess is too low.
Enter your guess number : 6
Your guess is too low.
Enter your guess number : 7
Your guess is too low.
Enter your guess number : 8
Your guess is too low.
Max number of guesses are over.
Better luck next time.Try again

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote