-
Notifications
You must be signed in to change notification settings - Fork 229
/
temp2.py
32 lines (27 loc) · 1.06 KB
/
temp2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
### PYTHON BOOT CAMP EXAMPLE;
### created by Josh Bloom at UC Berkeley, 2012 (ucbpythonclass+bootcamp@gmail.com)
### all rights reserved 2012 (c)
### https://github.com/profjsb/python-bootcamp
# set some initial variables. Set the initial temperature low
faren = -1000
# we dont want this going on forever, let's make sure we cannot have too many attempts
max_attempts = 6
attempt = 0
while faren < 100 and (attempt < max_attempts):
# let's get the user to tell us what temperature it is
newfaren = float(raw_input("Enter the temperature (in Fahrenheit): "))
if newfaren > faren:
print "It's getting hotter"
elif newfaren < faren:
print "It's getting cooler"
else:
# nothing has changed, just continue in the loop
continue
faren = newfaren
attempt += 1 # bump up the attempt number
if attempt >= max_attempts:
# we bailed out because of too many attempts
print "Too many attempts at raising the temperature."
else:
# we got here because it's hot
print "it's hot here, man."