I was working theough the exercises at
http://programming-crash-course.com/play_it_again_sam . I am having a simple problem solving what I thought would be just adding a chained conditional.
The intial code from there
print
# as the condition for this while loop is always true
# it will execute forever unless...
#
while True:
mpg = float(raw_input("What is the mileage? Enter 0 to stop: "))
print
# here is the unless part.
# if the user enters the value 0 the while loop will be broken
#
# the comparison operator is two equal signs "=="
# not only one "="
#
if mpg == 0:
# the if block also has to be indented
print 'The end...'
print
# the break instruction breaks the loop,
# be it a while loop or a for loop
#
break
# here in instead of building a list ourselves
# we let the range function build it for us
#
gallon_price_list = range(220, 250, 5)
for gallon_price in gallon_price_list:
cost = gallon_price / mpg
print 'gallon price in US$', gallon_price / 100.0,
print "cost in US$", cost, "per hundred miles"
print
The exercise was to change it to do this Proposed exercise
Break the while loop if the mileage is equal or lower than 0 or if the mileage is bigger than 100.
So I though I could just change the section
if mpg == 0:
to be
if 0 >= mpg >= 100
but that didn't work I tried many variations on that. Do I have to change the while true statement to be a if, elif, elif. statement.
I figured there must be a simple solution but I can't just see it.