Lecture 15 - Test 1 Review

Lecture Date: Monday, February 22

See the Test 1 Review Guide for information on what’s on the test.

higher/lower
1
2
3
4
5
6
7
8
9
10
11
12
13
14
print("Think of a number between 1 and 100")

highest_value = 100
lowest_value = 1
answer = "no"

while highest_value != lowest_value:
    answer = input("Is the number bigger than " + str((highest_value + lowest_value) // 2) + "? ")
    if answer == "yes":
        lowest_value = ((highest_value + lowest_value) // 2) + 1
    else:
        highest_value = ((highest_value + lowest_value) // 2)

print("Your number is " + str(highest_value))