07/12/15
Learning Objective:Understand how to create a loop in Python and use a Boolean variable to define when to stop
ITERATION - What is it?
What is the process of iteration?
What are the 2 types of iteration?
Who can tell me the difference between these 2 types of iterations?
Who can tell me the difference between these 2 types of iterations?
from random
import randint
myNumber
= randint(1, 100)
guessNum
= 0
numberGuessed
= False
guess
= 0
print
(I’m thinking of a number between 1 and 100…”)
print
(“Make a guess and I’ll tell you whether the number is higher or lower”)
while
numberGuessed == False:
guess = int(input(“Enter your guess: “))
guessNum += 1
if myNumber > guess:
print (“Higher”)
elif myNumber < guess:
print (“Lower”)
elif myNumber == guess:
print (“Well done you’ve guessed the number
in “ + str(guessNum) + “ guesses”)
numberGuessed = True
Comments
Post a Comment