|
Spring Semester 2007 |
The code does not show by default, it's up to you to make it show, when you're ready to look at it.
print """
4
4
4
4 4
44444444
4
4
"""The next program is almost the same:
print """
\"
\"
\"
\" \"
\"\"\"\"\"\"\"\"
\"
\"
"""However special characters require special treatment.
There isn't much that we can say about the next one:
print """
.8. 8 888888888o ,o888888o.
.888. 8 8888 `88. 8888 `88.
:88888. 8 8888 `88 ,8 8888 `8.
. `88888. 8 8888 ,88 88 8888
.8. `88888. 8 8888. ,88' 88 8888
.8`8. `88888. 8 8888888888 88 8888
.8' `8. `88888. 8 8888 `88. 88 8888
.8' `8. `88888. 8 8888 88 `8 8888 .8'
.888888888. `88888. 8 8888 ,88' 8888 ,88'
.8' `8. `88888. 8 888888888P `8888888P'
"""And with the next one things become really relevant (meaningful):
a = raw_input("Enter the lenght of the first side: ")
b = raw_input("Enter the lenght of the second side: ")
c = raw_input("Enter the lenght of the third side: ")
a = float(a)
b = float(b)
c = float(c)
s = (a + b + c) / 2.0
area = (s * (s - a) * (s - b) * (s - c)) ** 0.5
print "The area of the triangle is:", area Next one is a bit tricky. Can you say what is tricky about it?
a = raw_input("Enter your text:")
a = a.replace("e", "egge")
a = a.replace("a", "egga")
a = a.replace("e", "egge")
a = a.replace("i", "eggi")
a = a.replace("o", "eggo")
a = a.replace("u", "eggu")
print aHere's the program that calculates the maximum:
one = int(raw_input("Please enter the first number: "))
two = int(raw_input("Please enter the second number: "))
print one, "+", two, "=", one + two
print one, "-", two, "=", one - two
print one, "*", two, "=", one * two
print "avg(" + str(one) + ", " + str(two) + ") = ", (float(one) + two) / 2
print "dist(" + str(one) + ", " + str(two) + ") = ", abs(one - two)
print "max(" + str(one) + ", " + str(two) + ") = ", (one + two + abs(one - two)) / 2
print "min(" + str(one) + ", " + str(two) + ") = ", (one + two - abs(one - two)) / 2Here's the last program, that gives change:
due = raw_input("Due: ")
pay = raw_input("Pay: ")
change = int(100 * float(pay)) - int(100 * float(due))
print change / 25, " quarters"
change = change % 25
print change / 10, " dimes"
change = change % 10
print change / 5, " nickels"
change = change % 5
print change, " cents"The other programs discussed are being posted in a separate document.