CS代考 DSA8002 – Database & Programming Fundamentals

Module Info

DSA8002 – Database & Programming Fundamentals

Copyright By https://powcoder.com 加微信 powcoder

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])

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)

>>> sum_num_recursion(6)

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’)

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’])

>>> count_string([”, ‘x’, ‘xy’, ‘xyx’, ‘xx’])

>>> count_string([‘aaa’, ‘be’, ‘abc’, ‘hello’])

Lab Assessment Mocks

Page 2 of 2