This function definition has many parts:
two is the name of the function() is the parameter list (Here, it is empty)return 2 is a statement that causes the function to cease and produce the value 2add_one is the name of the function(n) is the parameter listreturn n + 1 is a statement that causes the function to cease and produce the value n + 1Remember this from the last set of slides?
Calculating the area of a circle is an abstraction.
In the code above, that is done by a variable assignment with a variable named area.
Let’s create a function called area, that given a radius parameter, it returns the area of the circle.
Write a function that does the following:
volumeradius and heightradius and height. Volume is area multiplied by height.What value will each of these variables take on? No computers!
a1 = 5 / 5 * 10 * 5 a2 = 5 / (5 * 10) * 5 b1 = 5 * 10 - 2 b2 = 5 * (10 - 2) c = (3 // (4 // 5)) + 1
a1 = 5 / 5 * 10 * 5
a2 = 5 / (5 * 10) * 5
b1 = 5 * 10 - 2
b2 = 5 * (10 - 2)
# c = (3 // (4 // 5)) + 1 ERROR -- Zero Division
print(a1)
print(a2)
print(b1)
print(b2)50.0
0.5
48
40
Note that the division operator returns a float even when both numerator and denominator are integers