Python-Basics-and-Unit-Tests
Python Basics and Unit Tests in Python, second year second semester's first Python project
Question 1
A code that receives an array of arrays containing integers and returns the sum of the numbers (without using list comprehension).
For example, for array [[3, 2], [1], [4, 12]], the number 22 is returned.
Question 2
- A program that receives a string and returns it in reverse order.
- A program that receives a list and returns it in reverse order. Note that an element in a list can be a list too. The internal list will also be returned in reverse order (Up to the first level. A list of lists. But on the inner level if there is a list it will be returned as it is and it does not need to be reversed).
- A program that receives a tuple and returns it in reverse order.
Question 3
- Program that receives tuple of sets. Each set can contain single characters or integers or decimal numbers. The program returns the elements that are the union of all sets when sorted. The sorting is done so that the characters are sorted first and then the numbers.
- The same program from section 1 - but this time the program returns a dictionary where the key to each element is its location after sorting.
Question 4
- The following program, without using if statements:
- The if in the above program in one line only.
Question 5
A program that receives two numbers from the user and prints all the even numbers in the range between these 2 numbers (including the edges), first in descending order and then in ascending order.
- Only with for loops
- Only with while loops
- Only with if statements