Arvutiteaduse instituut
  1. Kursused
  2. 2022/23 sügis
  3. Programmeerimise alused (MTAT.03.236)
EN
Logi sisse
Tähelepanu! Tehnilise tõrke tõttu on hetkel kättesaadavad vaid 2020.a. ja hilisemad üles laetud failid ja kevadsemestri kursused. Rikke kõrvaldamisega tegeletakse.

Programmeerimise alused 2022/23 sügis

  • Home
  • Grading
  • Links

Homework 6

The deadline is Thursday, the 13th of October, 23:59 (Estonian time).

Homework 6.1 Books and authors

Write a program that reads book titles and authors from a file called books.txt and displays the information found in file. Every line in file books.txt has the name of the book, "by" and the author's name. The result should contain the author first, followed by "wrote" and then the book name. For example: Joanne Rowling wrote Harry Potter. Also, use try and except blocks to handle file opening errors.

books.txt content:

 In Search of Lost Time by Marcel Proust
 Ulysses by James Joyce
 Don Quixote by Miguel de Cervantes
 Hamlet by William Shakespeare

The output of the program should be:

>>> %Run solution.py
Marcel Proust wrote In Search of Lost Time
James Joyce wrote Ulysses
Miguel de Cervantes wrote Don Quixote
William Shakespeare wrote Hamlet

If you have been struggling with this exercise for some time, maybe you can get help from troubleshooter: https://progtugi.cs.ut.ee#/ts/623aeacaef7eaf5634394b2b/. It tries to explain the most common problems and give hints.

Homework 6.2 Messy data

Row numbers got mixed up by accident in the data.txt file. Write a program that outputs all the lines from the file with the correct line numbers. The result should change only the integers displaying the row number, the first row should be 1. and the last one equal to a total number of rows.

Content of data.txt:

 3. First
 11. Second
 7. Third
 5. Fourth

Program output should be:

>>> %Run solution.py
1. First
2. Second
3. Third
4. Fourth

If you have been struggling with this exercise for some time, maybe you can get help from troubleshooter: https://progtugi.cs.ut.ee#/ts/623aed3cef7eaf5634394b62/. It tries to explain the most common problems and give hints.

Go to Moodle and upload your solution into Homework 6.

  • Arvutiteaduse instituut
  • Loodus- ja täppisteaduste valdkond
  • Tartu Ülikool
Tehniliste probleemide või küsimuste korral kirjuta:

Kursuse sisu ja korralduslike küsimustega pöörduge kursuse korraldajate poole.
Õppematerjalide varalised autoriõigused kuuluvad Tartu Ülikoolile. Õppematerjalide kasutamine on lubatud autoriõiguse seaduses ettenähtud teose vaba kasutamise eesmärkidel ja tingimustel. Õppematerjalide kasutamisel on kasutaja kohustatud viitama õppematerjalide autorile.
Õppematerjalide kasutamine muudel eesmärkidel on lubatud ainult Tartu Ülikooli eelneval kirjalikul nõusolekul.