7.6.EXERCISES 117
a, b, c = input(’Enter three numbers: ’)
if a > b:
if b > c:
print "SpamPlease!"
else:
print "It’sa late parrot!"
elif b > c:
print "CheeseShoppe"
if a >= c:
print "Cheddar"
elif a < b:
print "Gouda"
elif c == b:
print "Swiss"
else:
print "Trees"
if a == b:
print "Chestnut"
else:
print "Larch"
print "Done"
Show theoutputthatwouldresultfromeachofthefollowingpossibleinputs.
(a)3, 4, 5
(b)3, 3, 3
(c)5, 4, 3
(d)3, 5, 2
(e)5, 4, 7
(f)3, 3, 2
- Many companiespaytime-and-a-halfforany hoursworkedabove 40in a givenweek.Writea program
toinputthenumberofhoursworkedandthehourlyrateandcalculatethetotalwagesfortheweek.
- A certainCSprofessorgives5-pointquizzesthataregradedonthescale5-A,4-B,3-C,2-D,1-F, 0-F.
Writea programthatacceptsa quizscoreasaninputandusesa decisionstructuretocalculatethe
correspondinggrade.
- AcertainCSprofessorgives100-pointexamsthataregradedonthescale90–100:A,80–89:B,70–
79:C,60–69:D, 60:F. Writea programthatacceptsanexamscoreasinputandusesa decisionstruc-
turetocalculatethecorrespondinggrade.
- A certaincollegeclassifiesstudentsaccordingtocreditsearned.A studentwithlessthan7 creditsis a
Freshman.Atleast7 creditsarerequiredtobea Sophomore, 16 tobea Juniorand 26 tobeclassified
asa Senior. Writea programthatcalculatesclassstandingfromthenumberofcreditsearned.
- Thebodymassindex (BMI)is calculatedasa person’s weight(inpounds)times720,dividedbythe
squareoftheperson’s height(ininches).A BMIintherange19–25,inclusive, is consideredhealthy.
Writea programthatcalculatesa person’s BMIandprintsa messagetellingwhetherthey areabove,
withinorbelow thehealthyrange.
- Thespeedingticket finepolicy in Podunksvilleis $50plus$5foreachmphover thelimitplusa penalty
of$200forany speedover 90 mph.Writea programthatacceptsa speedlimitanda clockedspeed
andeitherprintsa messageindicatingthespeedwaslegalorprintstheamountofthefine,if thespeed
is illegal.