Module Info
DSA8002 – Database & Programming Fundamentals
2021/22
Mock Practical Test 1: Python Programming
ADMINISTRATION:
– The assessment is under normal University conditions so you will not bring lecture notes or any supporting materials, have access to the internet, email and are strictly prohibited to communicate to anyone during the assessment.
– You can use PyCharm or Spyder to develop and debug your python functions. Please use provided the testing cases to test your python functions before submission.
1. Write a function sum_odd_num() to calculate the sum of all odd numbers from a series of numbers. (25 marks)
>>> sum_odd_num([1, 2, 3, 4, 5, 6, 7, 8, 9])
25
2. Write a function to compute sum of a natural number list ended with N. For example, if N=6, the natural number list should be 1, 2, 3, 4, 5, and 6. Please implement both iterative version function sum_num_loop() and recursive version function sum_num_recursion(). (25 marks)
>>> sum_num_loop(6)
21
>>> sum_num_recursion(6)
21
3. Write a function mix_chars() to get a single string from two given strings, separated by a space and swap the first two characters of each string (25 marks)
>>> mix_chars(‘abc’, ‘xyz’)
‘xyc abz’
4. Given a list of strings, write a function count_string() to count the number of strings where the string length is 2 or more and the first and last chars of the string are the same. (25 marks)
>>> count_string([‘aba’, ‘xyz’, ‘aa’, ‘x’, ‘bbb’])
3
>>> count_string([”, ‘x’, ‘xy’, ‘xyx’, ‘xx’])
2
>>> count_string([‘aaa’, ‘be’, ‘abc’, ‘hello’])
1
Lab Assessment Mocks
Page 2 of 2