FIND THE VOLUME: 5 in 8 in 4 in
FIND THE VOLUME: 2 ft 6 in 3 ½ in
FIND THE VOLUME: ¼ m ½ m ¾ m
FIND THE VOLUME: 4.1 yd 8.6 yd 12.5 yd
Intro to Programming in Python Using computer programming to simplify and demonstrate understanding of geometry concepts
What is Python? Interpreted programming language Powerful for working with data Easy-to-learn syntax
Sample: Programming and Area length = 5 width = 6 units = “inches” area = length * width print “The area of this parallelogram is” , area, units, “squared” Output:
What’s going on here? This is all generic information about Python. It’s basically like starting an app – it tells you the version number and lets you know some commands These lines create variables length and width and give them numeric values This creates a variable with a STRING value This creates a variable whose value is the result of an expression – the earlier length times width Here I give the computer a command, to PRINT on the screen everything that follows (anything in quotes is printed exactly as written; anything outside of quotes, the computer thinks is a variable, so it prints its value instead Here is the computer’s response to my command!
That’s not very cool… How does the user know what the dimensions of the parallelogram are? What about other parallelograms?! This program only figures out the area of one specific parallelogram! How can someone else put in their own dimensions and units? I still have to show my work, and this only shows me the answer…
Let’s make our program better!
Area REVISED length = int(raw_input(“What is the length of the parallelogram?”)) width = int(raw_input(“What is the width of the parallelogram?”)) units = raw_input(“What are the units of the dimensions?”) area = length * width print “The area of this parallelogram is” , area, units, “squared” Output:
That’s not very cool… How does the user know what the dimensions of the parallelogram are? What about other parallelograms?! This program only figures out the area of one specific parallelogram! How can someone else put in their own dimensions and units? I still have to show my work, and this only shows me the answer…
Area REVISED AGAIN length = int(raw_input(“What is the length of the parallelogram?”)) width = int(raw_input(“What is the width of the parallelogram?”)) units = raw_input(“What are the units of the dimensions?”) area = length * width print “A = l * w” print “A = “ , length, units, “*” , width, units print “A = “ , area, units, “ squared” print “The area of this parallelogram is” , area, units, “squared”
How Could We Make This Even Better? Support someone entering mixed units (3 feet by 30 inches) Ask what kind of figure the user wants to find the area of, and compute appropriately Check to make sure the user doesn’t enter gibberish or stuff that doesn’t fit Figure out the perimeter too!