The program 'guess1'
import random
n = random.randrange(10)
g = int(input("Guess the number. "))
while g<n or g>n:
if g > n:
print ("Too high.")
elif g < n:
print ("Too low.")
g = int(input("Guess again. "))
else:
print ("Well done!")
input ("Press Enter to finish.")
It invites you to guess a mystery integer from 0 - 9. Pretty easy I think!
Computing:
Can you edit it so that you have to find an integer less than 100?
Can you make it so that the integer is greater than 0 and less than or equal to 100. Describe the algorithm if you can't imagine the code.
Computing and maths:
What strategies do you have for finding the mystery number in as few guesses as possible?
This program ('guess2') invites you to guess a number that is less than 10 but might have one decimal place.
import random
p = random.randrange(100)
n = p/10
g = float(input("Guess the number. "))
while g<n or g>n:
if g > n:
print ("Too high.")
elif g < n:
print ("Too low.")
g = float(input("Guess again. "))
else:
print ("Well done!")
input ("Press Enter to finish.")
Computing:
Change the program so that the target is less than 10 but has the possibility of two decimal places.
Now make the target number less than 100 with one or two decimal places.
Describe the rules for making the target number within the range you want.
Maths:
What do you need to know about multiplication and division by 10 to edit this program successfully?