Python programming

How do i write a module to keep count of the amount of guesses it takes to guess the number correctly?

Questions by robert25

Showing Answers 1 - 1 of 1 Answers

Code
  1. # This is a guess the number game.

  2. import random

  3. guessesTaken = 0

  4. print(Hello! What is your name?)

  5. myName = input()

  6. number = random.randint(1, 20)

  7. print(Well,  + myName + , I am thinking of a number between 1 and 20.)

  8. while guessesTaken < 6:

  9.     print(Take a guess.) # There are four spaces in front of print.

  10.     guess = input()

  11.     guess = int(guess)

  12.     guessesTaken = guessesTaken + 1

  13.     if guess < number:

  14.         print(Your guess is too low.) # There are eight spaces in front of print.

  15.     if guess > number:

  16.         print(Your guess is too high.)

  17.     if guess == number:

  18.         break

  19. if guess == number:

  20.     guessesTaken = str(guessesTaken)

  21.     print(Good job,  + myName + ! You guessed my number in  + guessesTaken +  guesses!)

  22. if guess != number:

  23.     number = str(number)

  24.     print(Nope. The number I was thinking of was  + number)


  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions