guessTheNumber1.py

# -*- coding: utf-8 -*-
"""
Created on Sat Feb  3 12:27:29 2018


@author: He Yuanwei
"""


# This is a guess the number game.
import random
secretNumber = random.randint(1,20)
print ('I am thinking of a number between 1 and 20.')
# Ask the player to guess 6 times.
for guessTaken in range(1, 7):
    guess = input('Take a guess.\n')
    
    if int(guess) < secretNumber:
        print ('Your guess is too low.')
        continue
    elif int(guess) > secretNumber:
        print ('Your guess is too high.')
        continue
    else:
        break #This condition is the correct guess!
if int(guess) == secretNumber:
    print ('Good job! You guessed my number in ' + str(guessTaken) + ' guesses!')
else:
    print('Nope. The number I was thinking of was ' + str(secretNumber))

你可能感兴趣的:(guessTheNumber1.py)