learningpython/number_guess.py

23 lines
662 B
Python
Executable file

#! /usr/bin/env python3
#guess the number game
import random
secretNumber = random.randint(1,100)
print('I am thinking of a number between 1 and 100.')
#ask the player to guess 10 times.
for guessesTaken in range(1,10):
print('take a guess')
guess = int(input())
if guess < secretNumber:
print('your guess is too low.')
elif guess > secretNumber:
print('your guess is too high.')
else:
break
if guess == secretNumber:
print('you guessed correctly! it only took you '+str(guessesTaken)+' guesses!')
else:
print('you were not able to guess in 10 guesses. the number I was thinking of was '+str(secretNumber))