Institute of Computer Science
  1. Courses
  2. 2019/20 fall
  3. Computer Programming (LTAT.03.001)
ET
Log in

Computer Programming 2019/20 fall

  • Pealeht
  • Videojuhised
  • Viiteid

13. kodutöö

1. Kasutatud auto hind rekursiivselt

Arvestame, et auto kaotab igal aastal väärtust 20% võrreldes eelmise aastaga. Kirjuta rekursiivne funktsioon (ehk funktsioon, mis kutsub välja iseennast), mis võtab sisse auto hinna ja aastate arvu ning tagastab, kui palju on auto väärt antud arvu aastate pärast. Funktsioon peab ümardama kõik tagastatavad hinnad kahe komakohani.

>>> auto_hind(10000.0, 0)
10000.0
>>> auto_hind(10000.0, 5)
3276.8
>>> auto_hind(10000.0, 1)
8000.0
>>> auto_hind(8000.0, 5)   # või auto_hind(10000.0, 6)
2621.44

Seda ülesannet saab lahendada ka while-tsükliga või valemiga, aga lahendamine rekursiivse funktsiooniga aitab hästi mõista rekursiooni mõtet.

2. Sarnaste ruutude fraktal

Kirjuta rekursiivne funktsioon, mis joonistab kilpkonnaga fraktali ruudust, mille kolmes nurgas on sarnased ruudud ning nende kolmes nurgas on ka sarnased ruudud ja nii edasi vastavalt funktsioonile etteantud sügavusele.

Joonisel on fraktalid, mis tekivad sügavuste 1, 2, 3 ja 4 puhul.

Automaatkontroll on olemas, aga ei kontrolli väljundpildi korrektsust.

  • 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