From e2e6b4c834f6ae8e9848ec4ab1e136b2334d89be Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Fri, 8 Oct 2021 18:11:33 +0300 Subject: [PATCH] task 150921 update --- task_061021/array_output.txt | 61 ++++++++++++++++ task_061021/book.txt | 38 +++++++++- task_061021/kacgulis_061021.py | 32 +++++++++ task_061021/main.py | 13 ---- task_061021/str_output.txt | 61 ++++++++++++++++ task_150921/kcagulis_150921.py | 79 +++++++++++++++++++++ task_150921/main.py | 30 -------- task_220921/kcagulis_220921.py | 24 +++++++ task_290921/{main.py => kcagulis_290921.py} | 30 ++++---- 9 files changed, 308 insertions(+), 60 deletions(-) create mode 100644 task_061021/array_output.txt create mode 100644 task_061021/kacgulis_061021.py delete mode 100644 task_061021/main.py create mode 100644 task_061021/str_output.txt create mode 100644 task_150921/kcagulis_150921.py delete mode 100644 task_150921/main.py create mode 100644 task_220921/kcagulis_220921.py rename task_290921/{main.py => kcagulis_290921.py} (64%) diff --git a/task_061021/array_output.txt b/task_061021/array_output.txt new file mode 100644 index 00000000..ac7aa473 --- /dev/null +++ b/task_061021/array_output.txt @@ -0,0 +1,61 @@ +Line 168 - Chapter 1 +Line 294 - Chapter 2 +Line 404 - Chapter 3 +Line 590 - Chapter 4 +Line 712 - Chapter 5 +Line 832 - Chapter 6 +Line 1120 - Chapter 7 +Line 1369 - Chapter 8 +Line 1634 - Chapter 9 +Line 1850 - Chapter 10 +Line 2147 - Chapter 11 +Line 2345 - Chapter 12 +Line 2421 - Chapter 13 +Line 2616 - Chapter 14 +Line 2747 - Chapter 15 +Line 2926 - Chapter 16 +Line 3315 - Chapter 17 +Line 3454 - Chapter 18 +Line 4023 - Chapter 19 +Line 4227 - Chapter 20 +Line 4424 - Chapter 21 +Line 4651 - Chapter 22 +Line 4840 - Chapter 23 +Line 5029 - Chapter 24 +Line 5247 - Chapter 25 +Line 5415 - Chapter 26 +Line 5663 - Chapter 27 +Line 5818 - Chapter 28 +Line 5980 - Chapter 29 +Line 6264 - Chapter 30 +Line 6398 - Chapter 31 +Line 6584 - Chapter 32 +Line 6765 - Chapter 33 +Line 6993 - Chapter 34 +Line 7230 - Chapter 35 +Line 7524 - Chapter 36 +Line 7733 - Chapter 37 +Line 7889 - Chapter 38 +Line 8013 - Chapter 39 +Line 8193 - Chapter 40 +Line 8393 - Chapter 41 +Line 8666 - Chapter 42 +Line 8865 - Chapter 43 +Line 9412 - Chapter 44 +Line 9652 - Chapter 45 +Line 9843 - Chapter 46 +Line 10157 - Chapter 47 +Line 10619 - Chapter 48 +Line 10872 - Chapter 49 +Line 11150 - Chapter 50 +Line 11387 - Chapter 51 +Line 11617 - Chapter 52 +Line 11960 - Chapter 53 +Line 12305 - Chapter 54 +Line 12504 - Chapter 55 +Line 12792 - Chapter 56 +Line 13145 - Chapter 57 +Line 13337 - Chapter 58 +Line 13622 - Chapter 59 +Line 13907 - Chapter 60 +Line 14093 - Chapter 61 diff --git a/task_061021/book.txt b/task_061021/book.txt index fced9d43..c3c09628 100644 --- a/task_061021/book.txt +++ b/task_061021/book.txt @@ -1,4 +1,40 @@ -Pride and Prejudice +The Project Gutenberg eBook of Pride and Prejudice, by Jane Austen + +This eBook is for the use of anyone anywhere in the United States and +most other parts of the world at no cost and with almost no restrictions +whatsoever. You may copy it, give it away or re-use it under the terms +of the Project Gutenberg License included with this eBook or online at +www.gutenberg.org. If you are not located in the United States, you +will have to check the laws of the country where you are located before +using this eBook. + +Title: Pride and Prejudice + +Author: Jane Austen + +Release Date: June, 1998 [eBook #1342] +[Most recently updated: August 23, 2021] + +Language: English + +Character set encoding: UTF-8 + +Produced by: Anonymous Volunteers and David Widger + +*** START OF THE PROJECT GUTENBERG EBOOK PRIDE AND PREJUDICE *** + + + + +THERE IS AN ILLUSTRATED EDITION OF THIS TITLE WHICH MAY VIEWED AT EBOOK +[# 42671 ] + +cover + + + + +Pride and Prejudice By Jane Austen diff --git a/task_061021/kacgulis_061021.py b/task_061021/kacgulis_061021.py new file mode 100644 index 00000000..ca64b72f --- /dev/null +++ b/task_061021/kacgulis_061021.py @@ -0,0 +1,32 @@ +# Author - Kristiāns Francis Cagulis +# Date - 06.10.2021 + +chapters = 61 + + +def read_array(): + with open('book.txt', encoding='utf-8') as book: + lines = [line.strip('\n') for line in book] # removes 'enter' characters + with open('array_output.txt', 'w') as output: + for i in range(1, chapters + 1): + line = lines.index(f"Chapter {i}") + 1 # finds all chapter indexes/lines + output.write(f"Line {line} - Chapter {i}\n") # writes line in file + + +def read_string(): + import re + with open('book.txt', encoding='utf-8') as book: + lines = book.read() + with open('str_output.txt', 'w') as output: + for i in range(1, chapters + 1): + _, position = re.finditer(rf"\bChapter {i}\b", lines) # finds all chapter positions + output.write(f"Position {position.start()} - Chapter {i}\n") # writes position in file + + +def main(): + read_array() + read_string() + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/task_061021/main.py b/task_061021/main.py deleted file mode 100644 index 05f201bf..00000000 --- a/task_061021/main.py +++ /dev/null @@ -1,13 +0,0 @@ -import re -with open('book.txt', encoding='utf-8') as book: - lines = book.read() - # lines = [line.strip() for line in book if "Chapter 1" in line] - # for line in lines: - # if line.strip() == "Chapter 1": - # var = [] - # var.append(line.strip()) - - results = re.search("Chapter 59", lines) - - # print(lines) - print(results) diff --git a/task_061021/str_output.txt b/task_061021/str_output.txt new file mode 100644 index 00000000..ffe8e443 --- /dev/null +++ b/task_061021/str_output.txt @@ -0,0 +1,61 @@ +Position 1803 - Chapter 1 +Position 6826 - Chapter 2 +Position 11611 - Chapter 3 +Position 22147 - Chapter 4 +Position 28689 - Chapter 5 +Position 34514 - Chapter 6 +Position 48891 - Chapter 7 +Position 61249 - Chapter 8 +Position 73481 - Chapter 9 +Position 84288 - Chapter 10 +Position 98151 - Chapter 11 +Position 108042 - Chapter 12 +Position 112369 - Chapter 13 +Position 122532 - Chapter 14 +Position 129641 - Chapter 15 +Position 140407 - Chapter 16 +Position 161366 - Chapter 17 +Position 169360 - Chapter 18 +Position 201447 - Chapter 19 +Position 213182 - Chapter 20 +Position 223335 - Chapter 21 +Position 235726 - Chapter 22 +Position 246675 - Chapter 23 +Position 256960 - Chapter 24 +Position 268884 - Chapter 25 +Position 278320 - Chapter 26 +Position 292366 - Chapter 27 +Position 300357 - Chapter 28 +Position 309423 - Chapter 29 +Position 324548 - Chapter 30 +Position 332321 - Chapter 31 +Position 341892 - Chapter 32 +Position 351255 - Chapter 33 +Position 362693 - Chapter 34 +Position 375902 - Chapter 35 +Position 394548 - Chapter 36 +Position 407468 - Chapter 37 +Position 416049 - Chapter 38 +Position 422597 - Chapter 39 +Position 432243 - Chapter 40 +Position 442382 - Chapter 41 +Position 456751 - Chapter 42 +Position 468455 - Chapter 43 +Position 498697 - Chapter 44 +Position 513387 - Chapter 45 +Position 524470 - Chapter 46 +Position 543018 - Chapter 47 +Position 567664 - Chapter 48 +Position 581505 - Chapter 49 +Position 595067 - Chapter 50 +Position 608801 - Chapter 51 +Position 621181 - Chapter 52 +Position 639508 - Chapter 53 +Position 657305 - Chapter 54 +Position 667112 - Chapter 55 +Position 681487 - Chapter 56 +Position 698485 - Chapter 57 +Position 708897 - Chapter 58 +Position 723991 - Chapter 59 +Position 738963 - Chapter 60 +Position 748616 - Chapter 61 diff --git a/task_150921/kcagulis_150921.py b/task_150921/kcagulis_150921.py new file mode 100644 index 00000000..03a4b07a --- /dev/null +++ b/task_150921/kcagulis_150921.py @@ -0,0 +1,79 @@ +# Author - Kristiāns Francis Cagulis +# Date - 15.09.2021 + + +# task 1 - train +def trains(): + # blue train from Jelgava to Riga + blue_train_speed = 57 + blue_train_time_driven = 10 / 60 + + # green train form Riga to Jelgava + green_train_speed = 60 + + # red train from Valka to Jelgava + red_train_speed = 60 + red_train_time_driven = 4 + + # distances + distance_riga_jelgava = 42 # from Riga to Jelgava (blue and green train) + distance_riga_valka = 164 # from Riga to Valka (red train) + + def blue_green_train(): + blue_train_already_driven_distance = blue_train_speed * blue_train_time_driven # blue train driven distance in 10 min + meeting_time = (distance_riga_jelgava - blue_train_already_driven_distance) / (blue_train_speed + green_train_speed) # time after which the two trains meet + green_train_distance = meeting_time * green_train_speed # distance green train has driven + meeting_distance = distance_riga_jelgava - green_train_distance # distance from meeting point to Riga + + return f"Zilais un zaļais vilciens tiksies {round(meeting_distance, 2)}km no Rīgas." + + def red_train(): + red_train_distance_driven = red_train_time_driven * red_train_speed # red train driven distance in given time + print(f"Sarkanais vilciens ir nobraucis {round(red_train_distance_driven, 2)}km.") + if red_train_distance_driven > distance_riga_valka: + return "Sarkanais vilciens ir pabraucis garām Rīgai." + + print(blue_green_train()) + print(red_train()) + + +# task 2 - sheep +def farm(): + sheep_amount = 255 # amount of sheep in farm + sheep_price = 20.5 # price per sheep's wool + wool_total_price = sheep_amount * sheep_price # price for all sheep wool + + additional_sheep = 120 # additional sheep + new_sheep_amount = sheep_amount + additional_sheep # sum of original and added sheep + new_wool_total_price = new_sheep_amount * wool_total_price # price for original and added sheep wool + + ostrich_amount = 15 # amount of ostrich in farm + ostrich_egg_price = 30 # price per egg + ostrich_time = 2 # time required to get one ostrich egg + days = 30 # the time when ostriches lay eggs + ostrich_egg_total_price = ostrich_amount * ostrich_egg_price * days / ostrich_time # price for all ostrich eggs in 30 days + + if wool_total_price >= ostrich_egg_total_price: + return "Iegūtās naudas pietiks, lai nopirktu visas mēneša olas." + else: + print("Iegūtās naudas nepietiks, lai nopirktu visas mēneša olas.") + if new_wool_total_price >= ostrich_egg_total_price: + return f"Ja aitu būtu par {additional_sheep}, tad iegūtās naudas pietiktu, lai nopirktu visas mēneša olas." + else: + return f"Ja aitu būtu par {additional_sheep}, tad iegūtās naudas nepietiktu, lai nopirktu visas mēneša olas." + + +def main(): + task = int(input("""Ivēlieties uzdevumu: + 1 - pirmais uzdevums + 2 - otrais uzdevums + """)) + + if task == 1: + trains() + elif task == 2: + print(farm()) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/task_150921/main.py b/task_150921/main.py deleted file mode 100644 index e4709fdd..00000000 --- a/task_150921/main.py +++ /dev/null @@ -1,30 +0,0 @@ -# Author - Kristiāns Francis Cagulis -# Date - 22.09.2021 -# -# Uzdevums: -# -# Firma apsolījusi Ziemassvētku bonusu 15% apjomā no mēneša algas par KATRU nostrādāto gadu virs 2 gadiem. -# Uzdevums. Noprasiet lietotājam mēneša algas apjomu un nostrādāto gadu skaitu. -# Izvadiet bonusu. - - -class Bonuss(): - def __init__(self): - self.percent = .15 - self.salary = float(input("Mēneša algas apjoms: ")) - self.time_worked = int(input("Nostrādātais gadu skaits: ")) - - def _calculate_bonus(self): - if self.time_worked > 2: - salary_bonus = self.percent * self.salary * (self.time_worked - 2) - return f"Jūsu algas bonuss ir {round(salary_bonus, 2)}€" - else: - return "Jums algas bonuss nepienākas." - - -def main(): - print(Bonuss()._calculate_bonus()) - - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/task_220921/kcagulis_220921.py b/task_220921/kcagulis_220921.py new file mode 100644 index 00000000..3b1d9846 --- /dev/null +++ b/task_220921/kcagulis_220921.py @@ -0,0 +1,24 @@ +# Author - Kristiāns Francis Cagulis +# Date - 22.09.2021 + + +class SalaryBonus(): + def __init__(self): + self.percent = .15 # percent + self.salary = float(input("Mēneša algas apjoms: ")) # salary per month + self.time_worked = int(input("Nostrādātais gadu skaits: ")) # number of years worked + + def _calculate_bonus(self): + if self.time_worked > 2: # if worked for more than 2 years + salary_bonus = self.percent * self.salary * (self.time_worked - 2) # calculates salary bonus + return f"Algas bonuss ir {round(salary_bonus, 2)}€" + else: + return "Algas bonuss nepienākas." + + +def main(): + print(SalaryBonus()._calculate_bonus()) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/task_290921/main.py b/task_290921/kcagulis_290921.py similarity index 64% rename from task_290921/main.py rename to task_290921/kcagulis_290921.py index 606ef5a6..533ffc73 100644 --- a/task_290921/main.py +++ b/task_290921/kcagulis_290921.py @@ -1,41 +1,39 @@ # Author - Kristiāns Francis Cagulis # Date - 29.09.2021 -import math +# task 1 - prime numbers +def is_prime(number): + import math -# 1. uzdevums -def is_prime(): - number = int(input("Ievadiet skaitli: ")) if number > 0: if number == 1: return "1 nav pirmsskaitlis" else: for i in range(2, int(math.sqrt(number)) + 1): if number % i == 0: - return f"Skaitlis {number} nav pirmsskaitlis" - return f"Skaitlis {number} ir pirmsskaitlis" + return f"{number} nav pirmsskaitlis" + return f"{number} ir pirmsskaitlis" else: return "Skaitlim jābūt lielākam par 0" -# 2. uzdevums +# task 2 - cities class Cities: def __init__(self, p0, perc, delta, p): - self.p0 = p0 - self.perc = float(perc[:-1]) / 100 - self.delta = delta - self.p = p + self.p0 = p0 # initial population + self.perc = float(perc[:-1]) / 100 # annual percentage population growth + self.delta = delta # number of arrivals (departures) per year + self.p = p # population size required def _calculate(self): years = 0 while (True): - result = self.p0 + self.p0 * self.perc + self.delta - self.p0 = result + self.p0 = self.p0 + self.p0 * self.perc + self.delta # calculate the new population in each year via the formula years += 1 - if result >= self.p: + if self.p0 >= self.p: # if the initial population reaches the required return f"{self.p} iedzīvotāju skaits tiks sasniegts pēc {years} gadiem" - if result < 0: + if self.p0 < 0: # if the required population is unreachable return -1 @@ -52,7 +50,7 @@ def main(): """)) if task == 1: - print(is_prime()) + print(is_prime(int(input("Ievadiet skaitli: ")))) elif task == 2: city = int(input("""Izvēlieties pilsētu: 0 - piemēra pilsēta