python-course.eu

11. Turkish Time and Clock

By Bernd Klein. Last modified: 01 Feb 2022.

Introduction

This chapter of our Python tutorial deals with turkish times. You will learn how to tell the time in turkish, but what is more him important: We will teach Python to tell the time in Turkish given the time numerically. Turkish grammar and sentence structures as well as vocabulary differ extremely from Indo-European languages like English and Persian, and also Semitic languages like Arabic and Hebrew and many other languages. So, telling the time in Turkish is also extremely difficult for speakers of English, German, French, Italian and many other languages. Fortunately, there are strict rules available. Rules which are so regular that it is easy to write a Python program to the job.

Turkish Time with Turkish flag

"Saat kaç?" means "What is the time?" in Turkish.

The task of hour program is to answer this question, given the time as string in the form "03:00" or "10:30".

We will need the words for the digits 0, 1, ... 9. We use a Pyhton list for this:

digits_list = ["bir", "iki", "üç", 
               "dört", "beş", "altı",
               "yedi", "sekiz", "dokuz"]  

The digits are not enough. We will need the words for the tens as well. The following list corresponds to the numbers "ten", "twenty", "thirty", "forty", and "fifty". We do not need more:

tens_list = ["on", "yirmi", "otuz",  "kırk",  "elli"]

Live Python training

instructor-led training course

Enjoying this page? We offer live Python training courses covering the content of this site.

See our Python training courses

See our Machine Learning with Python training courses

Verbal Representation of Numbers

Now, we need a function to transform any number between 1 and 59 to a turkish verbal representation. We can easily define this function, because it is more regular than in English. You will hopefully understand it by just looking at the function:

def num2txt(min):
    digits = min % 10
    tens = min // 10
    if digits > 0:
        if tens:
            return tens_list[tens-1] + " " + digits_list[digits-1]
        else:
            return digits_list[digits-1]
    else:
        return tens_list[tens-1]
    
for number in range(60):
    print(number, num2txt(number), end=", ")

OUTPUT:

0 elli, 1 bir, 2 iki, 3 üç, 4 dört, 5 beş, 6 altı, 7 yedi, 8 sekiz, 9 dokuz, 10 on, 11 on bir, 12 on iki, 13 on üç, 14 on dört, 15 on beş, 16 on altı, 17 on yedi, 18 on sekiz, 19 on dokuz, 20 yirmi, 21 yirmi bir, 22 yirmi iki, 23 yirmi üç, 24 yirmi dört, 25 yirmi beş, 26 yirmi altı, 27 yirmi yedi, 28 yirmi sekiz, 29 yirmi dokuz, 30 otuz, 31 otuz bir, 32 otuz iki, 33 otuz üç, 34 otuz dört, 35 otuz beş, 36 otuz altı, 37 otuz yedi, 38 otuz sekiz, 39 otuz dokuz, 40 kırk, 41 kırk bir, 42 kırk iki, 43 kırk üç, 44 kırk dört, 45 kırk beş, 46 kırk altı, 47 kırk yedi, 48 kırk sekiz, 49 kırk dokuz, 50 elli, 51 elli bir, 52 elli iki, 53 elli üç, 54 elli dört, 55 elli beş, 56 elli altı, 57 elli yedi, 58 elli sekiz, 59 elli dokuz, 

We will start now implementing the function translate_time. This function will produce a reply to the question "Saat kaç?". It takes hours and minutes as parameters. We will only implement the funciton for full hours, because this is the easiest case.

def translate_time(hours, minutes=0):
    if minutes == 0:
        return "Saat " + num2txt(hours) + "."
    else:
        return "I still do not know how to say it!"
    
for hour in range(1, 13):
    print(hour, translate_time(hour))

OUTPUT:

1 Saat bir.
2 Saat iki.
3 Saat üç.
4 Saat dört.
5 Saat beş.
6 Saat altı.
7 Saat yedi.
8 Saat sekiz.
9 Saat dokuz.
10 Saat on.
11 Saat on bir.
12 Saat on iki.

Easy, isn't it? What about "half past"? This is similar to English, if you consider that "buçuk" means "half". We extend our function:

def translate_time(hours, minutes=0):
    if minutes == 0:
        return "Saat " + num2txt(hours) + "."
    elif minutes == 30:
        return "Saat " + num2txt(hours) + " buçuk."
    else:
        return "I still do not know how to say it!"
    
for hour in range(1, 13):
    print(hour, translate_time(hour, 30))

OUTPUT:

1 Saat bir buçuk.
2 Saat iki buçuk.
3 Saat üç buçuk.
4 Saat dört buçuk.
5 Saat beş buçuk.
6 Saat altı buçuk.
7 Saat yedi buçuk.
8 Saat sekiz buçuk.
9 Saat dokuz buçuk.
10 Saat on buçuk.
11 Saat on bir buçuk.
12 Saat on iki buçuk.

We want to go on with telling the time in Turkish, and teach our Python program to say "a quarter past" and a "quarter to". It is getter more complicated or interesting now. Our Python implementation needs to learn some grammar rules now. The Python program has to learn now how to produce the Dative and the Accusative in Turkish.

Turkish Dative

The dative case is formed by adding e or a as a suffix to the end of the word (not necessarily a noun). If the last syllable of the word has one of the vowels 'a', 'ı', 'o' or 'u', an 'a' has to be added to the end of the word. If the last syllable of the word has one of the vowels 'e', 'i', 'ö', or 'ü', an 'e' has to be appended. One more important thing: Turkish doesn't like to vowels beside of each other. Therefore, we will add a "y" in front ot the 'e' or 'a', if the last letter of the word is a vowel.

Now we are ready to implement the dative function. It will suffix the dative ending to a given word. The dative function needs a function last_vowel which comes back with two values: