Arvutiteaduse instituut
  1. Kursused
  2. 2024/25 sügis
  3. Programmeerimise alused (MTAT.03.236)
EN
Logi sisse

Programmeerimise alused 2024/25 sügis

  • Home
  • Grading
  • Links

Before session 5

Strings

Watch the videos. Next two videos (part 1 and part 2) show how Python stores and manipulates textual data using string variables and functions.

Slides
Text-book: chapter 6 - strings

Test

Go to Moodle and take the fifth test.

Example 1. Estonian Personal Identifications Code

In Estonia, a personal identification number (Estonian: isikukood) is defined as a number formed primarily on the basis of the sex and date of birth of a person. The EPIN of each citizen is unique, therefore it is possible to identify the person by one's EPIN. The national ID-card, its associated certificates and digital signatures use the PINs.

An EPIN consists of 11 digits, generally given without any whitespace or other delimiters. The form is GYYMMDDSSSC, where G shows the sex and the century of birth (odd numbers for male, even numbers for female: 1-2 for male and female born in the 19th century, respectively; 3-4 for male and female born in the 20th century; 5-6 for male and female born in the 21st century), SSS is a serial number uniquely identifying people born on the same date, and C is the checksum.

The following program prompts the user for an EPIN, looks for his birthday date from the entered code and prints it out in the format dd.mm.yyyy:

code = input("Please enter a personal identification number: ")
#example code: 48007140350

date = code[5] + code[6]
month = code[3] + code[4]

if code[0] == "1" or code[0] == "2":
    century = "18"
elif code[0] == "3" or code[0] == "4":
    century = "19"
else:
    century = "20"

year = century + code[1] + code[2]

print("The birthday of the person with the code", code, "is", date+"."+month+"."+year)

Example 2. Room number from address

The following program prompts the user for an address. The program looks for and prints out the room number from the entered address (assume that the address is entered in the form of street_name building_number-room_number, town_name; e.g. Narva 18-2006, Tartu).

address = input("Please enter an address: ")

fpos = address.find("-")
lpos = address.find(",",fpos)

room = address[fpos+1:lpos]

print("Room number is", room)

Homework

The deadline for homework is Monday. You should start with homework already before the session.

Go to Lahendus and upload your solutions. Also do not forget to submit the logfiles for homework.

  • 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.
Courses’i keskkonna kasutustingimused