""" Felix Muzny DS 2000 Lecture 5 Write a program, hotcold.py, that randomly picks a number between 1 and 10 then has the user guess a number. If the user is correct, congratulate them. If the user is incorrect, prompt them to guess again. Each time the user guesses tell them "warmer" if they are getting closer to the secret number and "colder" if they are getting farther away. """ # import random module import random def main(): # generate a random int [1, 10] (inclusive) num = random.randint(1, 10) print("random num:", num) # 1 set initial values of important variables guess = int(input("guess? ")) prev_guess = 0 # 2 test to see if the loop should repeat while guess != num: # absolute value curr_dist = abs(guess - num) prev_dist = abs(prev_guess - num) print("curr", curr_dist) print("prev", prev_dist) # tell the user if they are warmer or colder if prev_dist > curr_dist: print("warmer") else: print("colder") # 3) update values, in particular # guess -- which will stop the program prev_guess = guess guess = int(input("new guess? ")) # you KNOW guess == num at this point print("you won!") main()