2026-11-11
Max. 100 points
Name:
| Task | Max. | Achieved |
|---|---|---|
| 1 | 24 | |
| 2 | 25 | |
| 3 | 30 | |
| 4 | 21 | |
| Sum | 100 |
| Statement | True | False |
|---|---|---|
for loops are used for repeated execution as
long as an expression is true. | ||
| In Python it is recommended to use five spaces for indentation. | ||
| A function can be considered a named suite of code that can be parameterized. | ||
| Python code can be edited with any text editor. | ||
| In Python, strings are mutable. | ||
| Python blocks create a new scope. |
def sum(a, b, c):
return a + b + c
print(sum(4, 2))
s = 'c++'
print(s.upper())
import math
round(math.sin(0.0))
s = 'Peace'
s[0] = 'p'
def fun(a, b, c=5):
return a + b + c
print(fun(10, 5))
is_leap(year: int) -> bool.
Given a year as a number, report if it is a leap year. A leap year occurs:
is_leap(1981) returns False,
is_leap(1984) returns True,
is_leap(1900) returns False while
is_leap(2000) returns True.
Document your function with a docstring.
(30 points)
def is_leap(year):
"""Return True if the given year is a leap year, otherwise false."""
if year % 400 == 0:
return True
if year % 100 == 0:
return False
if year % 4 == 0:
return True
return False
surface_sphere(r)
surface_cylinder(r, h)
volume_cylinder(r, h)
The required formulas in the order of the functions above are
import math
def surface_sphere(r):
"""Return the surface of a sphere with radius r."""
return 4 * math.pi * r * r
def surface_cylinder(r, h):
"""Return the surface of a cylinder with radius r and height h."""
return 2 * r * r * math.pi + 2 * r * math.pi * h
def volume_cylinder(r, h):
"""Return the volume of a cylinder with radius r and height h."""
return r * r * math.pi * h