1AKIFT POS Test (Group A)

2023-11-15

Max. 100 points

Name:

Task Max. Achieved
1 12
2 12
3 24
4 24
5 28
Sum 100
Grading: >= 88: 1, >=76: 2, >=64 : 3, >=51: 4, <=50: 5
  1. Python
    Answer the following statements indicating whether they are True or False.
    0-3 correct: 0 points, 4 correct: 4 points, 5 correct: 8 points, 6 correct: 12 points.
    Statement True False
    In Python, the mem keyword is used to determine if a value is a member of a sequence.
    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 supports keyword arguments and default parameters.
  2. DVCS and pair programming
    Answer the following statements indicating whether they are True or False.
    0-3 correct: 0 points, 4 correct: 4 points, 5 correct: 8 points, 6 correct: 12 points.
    Statement True False
    Git is a distributed version control system.
    It is possible to work only on a single computer without a central server when using git.
    git crunch completely removes old versions to save disk space.
    git commit records changes to a repository.
    Pair programming helps to distribute skills and knowlege in a team.
    Both programmers write code simultaneously when doing pair programming.
  3. What is the output of the following code snippets? Write exactly what the output of each snippet is if the snippet is the sole content of a Python file. If the output is an error message, it is enough to write “ERROR”. If there is no visible output, write "-".
    4 points for each correct answer.
    1. def sum(a, b, c):
          return a + b + c
      print(sum(4, 2))
      ERROR
    2. def area(length):
          return length ** 2
      print(circumference(5, 2))
      ERROR
    3. s = 'Hello World!'
      s = s.lower()
      print(s)
      hello world!
    4. s = 'Peace'
      print(s.append('!'))
      ERROR
    5. def fun(a, b, c=5):
          return a + b + c
      print(fun(10, 5))
      20
    6. def print_together(a, b):
          print(a, b)
      print_together(b='World!', a='Hello')
      Hello World!
  4. Implement the function is_leap(year: int) -> bool. Given a year as a number, report if it is a leap year. A leap year occurs: For example, 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)
    4 points for the correct function signature
    4 points for a proper docstring
    4 points for returning `True` for years evenly divisible by 400
    4 points for returning `False` for years evenly divisible by 100
    4 points for returning `True` for years evenly divisible by 4
    4 points for returning `False` for all other years
    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
  5. Implement the following functions:
    surface_sphere(r)
    volume_sphere(r)
    surface_cylinder(r, h)
    volume_cylinder(r, h)
    The required formulas in the order of the functions above are Each of the functions has to have a proper docstring. (28 points)
    2 points for each correct function signature
    2 points for each proper docstring
    3 points for each correct return value
    import math
    
    def surface_sphere(r):
        """Return the surface of a sphere with radius r."""
        return 4 * math.pi * r * r
    
    
    def volume_sphere(r):
        """Return the volume of a sphere with radius r."""
        return 4.0 / 3 * math.pi * r * 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