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: 3907070 • 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.

Explanation / Answer

Implemented code as per the requirement. Please comment if you face any difficulty.

As python is tab specific, please maitain the tab spaces in the code as specified below. Commented how many tab spaces you have to maintain before each line. Please follow accordingly.

import random
count = 0
rand = random.randint(1,10)
while(1):

#Here onwards TAB spces need to maintain. How TABS you have to maintain specified in a comment form.

#TAB
inp = input("Enter a number: ")
#TAB
if(inp==rand):
#TAB TAB
count = count+1
#TAB TAB
if(count==1):
#TAB TAB TAB
print "Awesome!!! You guessed it in first attempt"
#TAB TAB
else:
#TAB TAB TAB
print "Nice.. You guessed it in ",count," attempts"
#TAB TAB
break
#TAB
else:
#TAB TAB
count = count+1
#TAB TAB
print "Your guess is wrong. Please 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