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

If I could get help with this hw problem, that would be great! Write a text-base

ID: 3856098 • Letter: I

Question

If I could get help with this hw problem, that would be great!

Write a text-based program that plays a simple number guessing game with the user: when the program starts, it picks a random number between 1 and 100 (not telling the user what it is!) and the user proceeds to make guesses of what it is. When the user makes a guess, tell her whether she's too high or too low; she wins the game when she's correct. She should also be able to enter "q" to give up and quit. When she wins the game, tell her how many guesses she made.

This is a beginner course, so the program can be kept fairly simple. I have no experience with programming, so most stuff is all new to me.

The main topics of our lectures/chapter this week were Indefinite (while) loops, File loops, Nested loops, Boolean logic, Nesting if statements and loops.

Explanation / Answer

# this is a number guessing game
import random

correctNumber = random.randint(1,100) # this returns random number from 1 to 100
count = 0
while (True):
   guess = input ('Enter your guess: ')
   if guess == 'q':
       print('Quit')
       break
   guess = int(guess)
   count = count + 1 # keeps track of the number of guesses
   if abs(guess-correctNumber) >= 10:
       if (guess > correctNumber):
           print ('Your guess is too High!')
       else:
           print ('Your guess is too Low!')

   elif guess == correctNumber:
       print ('Correct! You made ' + str(count) + ' guesses.')
       break
   else:
       print ('You're close!')

OUTPUT:

$python guessinggame.py

Enter your guess: 50
Your guess is too High!
Enter your guess: 40
Your guess is too High!
Enter your guess: 30
You're close!
Enter your guess: 20
You're close!
Enter your guess: 15
Your guess is too Low!
Enter your guess: 35
You're close!
Enter your guess: 25
You're close!
Enter your guess: 26
You're close!
Enter your guess: 27
Correct! You made 9 guesses.

NOTE: I have written this program in python3.

If you need the code in python2 or any other language such as java, c, c++, etc, just let me know in the comments. I will be glad to help you with it.

If helpful, do click on the thumbs up button. Thank you.

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