So I've been tossing some sample problems at my AP students in preparation for the HS Programming Contest at Kansas State University later this fall. If I'm not busy with something else, I'm working on solving it myself for my own practice.
For the one from a couple days ago, I only had time to start the skeleton of the idea and didn't finish it to the full requirements of the problem. I showed them what I wrote this morning, as most of them were still battling the overall structure to approach the problem.
It was really nice, even as the teacher, to hear one of my students (and one of the best coders in the class) look at what I wrote and say, "That is beautiful code, man."
Here is what I wrote, feel free to shred me if you catch anything. Ultimately the problem included taking three entries, comparing them, and then giving output on which entry was the largest and whether it was a "t", "s", or "r".
def main():
print('Enter object types as t for triangle, r for rectangle, and s for sqaure.')
print('Enter numbers only for dimension values.')
print()
firstObjectType = input('Enter type of first object: ')
if firstObjectType == 't':
h = int(input('Enter height of triangle: '))
b = int(input('Enter base of triangle: '))
object1 = triangleCalc(b, h)
print(object1)
def triangleCalc(base, height):
tArea = 0.5 * base * height
return tArea
def squareCalc(sideLength):
sArea = sideLength * sideLength
return sArea
def rectangleCalc(length, width):
rArea = length * width
return rArea