2023-12-13
Max. 100 points
Name:
Task | Max. | Achieved |
---|---|---|
1 | 12 | |
2 | 12 | |
3 | 24 | |
4 | 24 | |
5 | 28 | |
Sum | 100 |
Statement | True | False |
---|---|---|
In Python, the fast keyword is used to
speed up the execution of a function. | ||
In Python it is recommended to use four spaces for indentation. | ||
A function is used to exit a loop. | ||
Python code written with micro can afterwards be edited with any text editor. | ||
In Python, lists are mutable. | ||
Python does not support default parameters. |
Statement | True | False |
---|---|---|
Git is a sophisticated programming editor. | ||
Git can take care of files in many different programming languages. | ||
git clone downloads a repository from a
server. | ||
git commit records changes to a repository. | ||
Pair programming improves code quality. | ||
The driver writes the code while the navigator assists. |
def sum(a, b):
return b + c
print(sum(4, 2))
def area(length):
return length ** 2
print(area(5))
s = 'Hello World!'
s.lower()
print(s)
s = 'Peace'
print(s.upper())
def fun(a, b=5, c):
return a + b + c
print(fun(10, 5))
def print_together(a, b):
print(a, b)
print_together(b='XMAS!', a='Merry')
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.
(24 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
area_circle(r)
circumference_circle(r)
surface_cylinder(r, h)
volume_cylinder(r, h)
The required formulas in the order of the functions above are
import math
def area_circle(r):
"""Return the surface of a sphere with radius r."""
return math.pi * r * r
def circumference_circle(r):
"""Return the volume of a sphere with radius r."""
return 4 * math.pi * 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