Institute of Computer Science
  1. Courses
  2. 2018/19 fall
  3. Computer Programming (Narva College) (SVNC.00.054)
ET
Log in

Computer Programming (Narva College) 2018/19 fall

  • Home
  • Grading
  • Links

During session 14

Exercises

NB! The practical session exercises are always provided enough and to spare with an eye to fast / experienced students have exercises to solve. To this end, do not get upset if you do not get on all the task in class. Take your time and complete the tasks at home!

1. Fractal

The following image contains examples of the fractal of order 0, 1, 2, 3 and 4. Write a recursive function, which takes two arguments: the order of the fractal and the length of a side. The function has to draw the fractal of the corresponding order. Demonstrate the work of the function drawing the fractal of order 4.

2. Cesaro fractal

Upgrade the previous program so that it draws the following fractal:

Hint: you can use a loop and the recursive function defined in previous exercise.

3. Recursive exponentiation

Write a recursive function that takes two numbers as its arguments and returns the first number raised into the power of the second number. it is not allowed to use loops, operator ** or the built-in function math.pow().

Hint: exponentiation corresponds to the repeated multiplication of the base.

4. Recursive number of elements

Write a recursive function number_of_elements that takes a recursive data structure (a nested list) and returns the number of all the elements (count all elements in all lists). It is not allowed to use the built-in function len.

Examples of the function call:

>>> number_of_elements([1, [2, 3], [[[[4, 5], 6]]], 7, 8])
8
>>> number_of_elements([[1, [2, [3, 4], 5], [6, 7, 8]], [9, 10]])
10
>>> number_of_elements([1, 2, [3, 4, 5, 6], 7, [8], 9])
9
>>> number_of_elements([1, 2, 3])
3

Sample exam exercises

Check out some examples of the test and the programming exercises:

  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment