##### Simple Excercise: what does the following print? (run to find out)
a = 0;
while a<4:
b = 0
while b<5:
print a, b
b = b+1
# end while b
print "---"
a = a+1
# end while a
##### Count ways to make change for 1 dollar:
ways = 0
q = 0 # quarters
while q*25 <= 100:
d = 0 # dimes
while d*10 + q*25 <= 100:
n = 0 # nickels
while (n*5 + d*10 + q*25 <= 100):
p = 100 - (n*5) - (d*10) - q*25
print q," quarters, ",d," dimes, ",n," nickels and ",p," pennies"
ways = ways+1
n = n+1
# nickels loop
d = d+1
# dimes loop
q = q+1
# quarters loop
print "there are ",ways," ways to make change for a dollar"
####### print calendar with dates: (not a nested loop)
nd = 1 # months always start at day 1
end = 31 # months end at day 28-31
dayw = 2 # say this month starts on a Wednesday: (monday is day 0)
print "\nMon\tTue\tWed\tThr\tFri\tSat\tSun"
# print initial skips
i = 0;
while i6:
print "" # new line
dayw = 0 # reset day of week to monday
# end loop
print "\n", dayw # start date of next month
#**************** Function to return day of week given date and day of
#week the month started at.
# 0 is monday, 6 is sunday
def day(start,n):
Days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
# find index of start string in array Days
i = 0
while i31): raise Exception("very funny")
return Days[ (i+n-1) % 7 ]
# day
print day("Wednesday",17), day("Wednesday",27), day("Wednesday",31)