Solve the Problem -Python
Guessing Game
import random
guessesTaken = 0
print('Hello! What is your name?')
userName = input()
number = random.randint(1, 100)
print('Well, ' + userName + ', I am thinking of a number between 1 and 100.')
while guessesTaken < 6:
print('Take a guess.') # There are four spaces in front of print.
guess = input()
guess = int(guess)
guessesTaken = guessesTaken + 1
if guess < number:
print('Your guess is too low.') # There are eight spaces in front of print.
if guess > number:
print('Your guess is too high.')
if guess == number:
break
if guess == number:
guessesTaken = str(guessesTaken)
print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
if guess != number:
number = str(number)
print('Nope. The number I was thinking of was ' + number)
import random
guessesTaken = 0
print('Hello! What is your name?')
userName = input()
number = random.randint(1, 100)
print('Well, ' + userName + ', I am thinking of a number between 1 and 100.')
while guessesTaken < 6:
print('Take a guess.') # There are four spaces in front of print.
guess = input()
guess = int(guess)
guessesTaken = guessesTaken + 1
if guess < number:
print('Your guess is too low.') # There are eight spaces in front of print.
if guess > number:
print('Your guess is too high.')
if guess == number:
break
if guess == number:
guessesTaken = str(guessesTaken)
print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
if guess != number:
number = str(number)
print('Nope. The number I was thinking of was ' + number)
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment