Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

python loop help?

Update:

i need help instrumenting a loop to show the value of guesses taken in a guess my number game i have to do for python.

heres the code i have for the program:

Update 2:

# This is a guess the number game.

import random

guessesTaken = 0

print('Hello! What is your name?')

myName = input()

number = random.randint(1, 20)

print('Well, ' + myName + ', 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 too low.')

if guess > number:

print('Your guess is too high.')

Update 3:

im not gonna put the rest of the code on here cause thats not what i need help with but i need help with instrumenting a loop where it will show the value of guesses taken.

Update 4:

heres the rest of the code if you really need it:

if guess == number:

break

if guess == number:

guessesTaken = str(guessesTaken)

print('Good job, ' + myName +'! You guesses my number in ' +

guessesTaken + ' guesses!')

if guess != number:

number = str(number)

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

2 Answers

Relevance
  • 7 years ago

    I'm slightly confused... You have already implemented the loop.

    are you wanting to store numbers previous guessed? then have a message informing the user of numbers they have already guessed? or... just a message that informs the user what guess number they are on. For example 1st guess, 2nd guess... last guess

    Here is a way to do the latter - http://pastebin.com/j9UEfTgP

  • ?
    Lv 6
    7 years ago

    sorry, only python loop i can help you with is the one it throws around your neck if it gets out of it's cage ;)

Still have questions? Get your answers by asking now.