The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 3 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Modify the Guess My Number Chapter Project from Chapter 3 by reusing the function ask_number() from the Tic-Tac-Toe Chapter Project from this chapter. Replace the code in Guess My Number that asks the player for a guess with a call to ask_number( ).
Here is the original Guess My Number game:
import random
guessesTaken = 0
print("Hello what is your name?")
name = input()
number = random.randint(1,20)
print("Well",name,",I am thinking of a number between 1 and 20.")
while guessesTaken < 6:
   print("Take a guess")
   guess = input()
   guess = int(guess)
   guessesTaken = guessesTaken + 1
   if guess < number:
       print("your guess is to low")
   if guess > number:
       print("Your guess is to high")
   if guess == number:
       break
if guess == number:
   guessesTaken = str(guessesTaken)
   print("Good job",name,"You guessed my number in",guessesTaken,"guesses!")
if guess != number:
   number = str(number)
   print("Nope, the number I was thinking of was",number)
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll