From 660bf2077c88a63a6fde937b451210233538a713 Mon Sep 17 00:00:00 2001 From: sarawone Date: Sat, 1 Aug 2026 11:04:06 +0100 Subject: [PATCH 1/9] exercise1.1 --- .github/Perp-Exercise/exercise1.1.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .github/Perp-Exercise/exercise1.1.py diff --git a/.github/Perp-Exercise/exercise1.1.py b/.github/Perp-Exercise/exercise1.1.py new file mode 100644 index 000000000..2c5482f9b --- /dev/null +++ b/.github/Perp-Exercise/exercise1.1.py @@ -0,0 +1,8 @@ +def double(value): + return value * 2 +#Question +#Predict what double("22") will do. Then run the code and check. Did it do what you expected? Why did it return the value it did? + +#Answer +# it will return "2222" +#In python, the string*number shows the number of times of the string. \ No newline at end of file From 8636c311b3e1c703864190bca4a62c42111f5352 Mon Sep 17 00:00:00 2001 From: sarawone Date: Sat, 1 Aug 2026 11:09:45 +0100 Subject: [PATCH 2/9] exercise_1.2 --- .github/Perp-Exercise/exercise1.2.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/Perp-Exercise/exercise1.2.py diff --git a/.github/Perp-Exercise/exercise1.2.py b/.github/Perp-Exercise/exercise1.2.py new file mode 100644 index 000000000..6aec08336 --- /dev/null +++ b/.github/Perp-Exercise/exercise1.2.py @@ -0,0 +1,12 @@ +def double(number): + return number * 3 + +print(double(10)) + +#Question +#Read the above code and write down what the bug is. How would you fix it? + +#Answer + +#The code is correct but the function name as double but the code is calculated for Triple . +#I can fix with two method. 1. change to function name to triple 2. change return number *3 to number *2 From a89b858ad9d75114296d786f68d59a83ebb6e42d Mon Sep 17 00:00:00 2001 From: sarawone Date: Sat, 1 Aug 2026 12:10:34 +0100 Subject: [PATCH 3/9] exercise2 --- .../exercise1.1.py | 0 .../exercise1.2.py | 0 Perp-Exercise/exercise2.py | 32 +++++++++++++++++++ 3 files changed, 32 insertions(+) rename {.github/Perp-Exercise => Perp-Exercise}/exercise1.1.py (100%) rename {.github/Perp-Exercise => Perp-Exercise}/exercise1.2.py (100%) create mode 100644 Perp-Exercise/exercise2.py diff --git a/.github/Perp-Exercise/exercise1.1.py b/Perp-Exercise/exercise1.1.py similarity index 100% rename from .github/Perp-Exercise/exercise1.1.py rename to Perp-Exercise/exercise1.1.py diff --git a/.github/Perp-Exercise/exercise1.2.py b/Perp-Exercise/exercise1.2.py similarity index 100% rename from .github/Perp-Exercise/exercise1.2.py rename to Perp-Exercise/exercise1.2.py diff --git a/Perp-Exercise/exercise2.py b/Perp-Exercise/exercise2.py new file mode 100644 index 000000000..ddd3807f8 --- /dev/null +++ b/Perp-Exercise/exercise2.py @@ -0,0 +1,32 @@ +# adding type annotation + +def open_account(balances: dict[str,int], name:str, amount: float) -> None: + balances[name] = amount + +def sum_balances(accounts: dict[str,int]) ->int: + total = 0 + for name, pence in accounts.items(): + print(f"{name} had balance {pence}") + total += pence + return total + +def format_pence_as_string(total_pence: int) -> float: + if total_pence < 100: + return f"{total_pence}p" + pounds = int(total_pence / 100) + pence = total_pence % 100 + return f"£{pounds}.{pence:02d}" + +balances: dict[str,int] = { + "Sima": 700, + "Linn": 545, + "Georg": 831, +} + +open_account("Tobi", 9.13) +open_account("Olya", "£7.13") + +total_pence = sum_balances(balances) +total_string = format_pence_as_str(total_pence) + +print(f"The bank accounts total {total_string}") \ No newline at end of file From 8ffbcf36cf264160637317e0fde72f0c5b44addf Mon Sep 17 00:00:00 2001 From: sarawone Date: Sat, 1 Aug 2026 12:11:06 +0100 Subject: [PATCH 4/9] updating exercise2 --- Perp-Exercise/exercise2.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Perp-Exercise/exercise2.py b/Perp-Exercise/exercise2.py index ddd3807f8..f2df260ad 100644 --- a/Perp-Exercise/exercise2.py +++ b/Perp-Exercise/exercise2.py @@ -1,6 +1,6 @@ # adding type annotation -def open_account(balances: dict[str,int], name:str, amount: float) -> None: +def open_account(balances: dict[str,int], name:str, amount: int) -> None: balances[name] = amount def sum_balances(accounts: dict[str,int]) ->int: @@ -10,7 +10,7 @@ def sum_balances(accounts: dict[str,int]) ->int: total += pence return total -def format_pence_as_string(total_pence: int) -> float: +def format_pence_as_string(total_pence: int) -> str: if total_pence < 100: return f"{total_pence}p" pounds = int(total_pence / 100) @@ -23,10 +23,11 @@ def format_pence_as_string(total_pence: int) -> float: "Georg": 831, } -open_account("Tobi", 9.13) -open_account("Olya", "£7.13") +#changing float to int (9.13 to 913) +open_account(balances,"Tobi", 913) +open_account(balances,"Olya", 713) total_pence = sum_balances(balances) -total_string = format_pence_as_str(total_pence) +total_string = format_pence_as_string(total_pence) #correct the function name print(f"The bank accounts total {total_string}") \ No newline at end of file From ba3106cabad9921f4029eb687a54cb9589b487db Mon Sep 17 00:00:00 2001 From: sarawone Date: Sat, 1 Aug 2026 13:00:43 +0100 Subject: [PATCH 5/9] exercise3 --- Perp-Exercise/exercise3.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Perp-Exercise/exercise3.py diff --git a/Perp-Exercise/exercise3.py b/Perp-Exercise/exercise3.py new file mode 100644 index 000000000..ca1ddefb1 --- /dev/null +++ b/Perp-Exercise/exercise3.py @@ -0,0 +1,28 @@ +class Person: + def __init__(self, name: str, age: int, preferred_operating_system: str): + self.name = name + self.age = age + self.preferred_operating_system = preferred_operating_system + +imran = Person("Imran", 22, "Ubuntu") +print(imran.name) +print(imran.age) + +eliza = Person("Eliza", 34, "Arch Linux") +print(eliza.name) +print(eliza.age) + +def is_adult(person: Person) -> bool: + return person.age >= 18 + +print(is_adult(imran)) + +#new function +ayk = Person("AYK",36,"Linux") + +def get_info(person: Person): + print(person.address) + + + +result = get_info(ayk) \ No newline at end of file From ff79b701b9af19181ec9f29b79a9e276be5c2e56 Mon Sep 17 00:00:00 2001 From: sarawone Date: Sun, 2 Aug 2026 09:20:09 +0100 Subject: [PATCH 6/9] exercise4 --- Perp-Exercise/exercise4.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Perp-Exercise/exercise4.py diff --git a/Perp-Exercise/exercise4.py b/Perp-Exercise/exercise4.py new file mode 100644 index 000000000..70c6826cb --- /dev/null +++ b/Perp-Exercise/exercise4.py @@ -0,0 +1,25 @@ +import datetime as dt + +class Person: + def __init__(self, name: str, dob: dt.date, preferred_operating_system: str): + self.name = name + self.dob = dob + self.preferred_operating_system = preferred_operating_system + + def get_age(self) -> int : + today = dt.date.today() + return today.year - self.dob.year + +imran = Person("Imran", dt.date(1990,8,22), "Ubuntu") +print(imran.name) +print(imran.dob) +print(imran.get_age()) + + + + + + + + + From 425ada5229753938f739a17c4e050069e38f297d Mon Sep 17 00:00:00 2001 From: sarawone Date: Sun, 2 Aug 2026 10:41:09 +0100 Subject: [PATCH 7/9] exercise5 --- Perp-Exercise/exercise5.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Perp-Exercise/exercise5.py diff --git a/Perp-Exercise/exercise5.py b/Perp-Exercise/exercise5.py new file mode 100644 index 000000000..cd2711c5e --- /dev/null +++ b/Perp-Exercise/exercise5.py @@ -0,0 +1,26 @@ +import datetime as dt +from dataclasses import dataclass + +@dataclass +class Person: + name: str + dob: dt.date + preferred_os:str + + def get_age(self) -> int : + today = dt.date.today() + return today.year - self.dob.year + +imran = Person("Imran", dt.date(1990,8,22), "Ubuntu") +print(imran.name) +print(imran.dob) +print(imran.get_age()) + + + + + + + + + From 9e08e804c2eb44485d7bc3f14c8fd8b1d6af52fe Mon Sep 17 00:00:00 2001 From: sarawone Date: Sun, 2 Aug 2026 10:58:28 +0100 Subject: [PATCH 8/9] exercise6 --- Perp-Exercise/exercise6.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Perp-Exercise/exercise6.py diff --git a/Perp-Exercise/exercise6.py b/Perp-Exercise/exercise6.py new file mode 100644 index 000000000..24eb58b16 --- /dev/null +++ b/Perp-Exercise/exercise6.py @@ -0,0 +1,20 @@ +from dataclasses import dataclass +from typing import List + +@dataclass(frozen=True) +class Person: + name: str + children: List["Person"] + age: int + +fatma = Person(name="Fatma", children=[],age=5) +aisha = Person(name="Aisha", children=[],age=7) + +imran = Person(name="Imran", children=[fatma, aisha],age=40) + +def print_family_tree(person: Person) -> None: + print(person.name,person.age) + for child in person.children: + print(f"- {child.name} ({child.age})") + +print_family_tree(imran) \ No newline at end of file From 39f818c8c128e28920c6fc03dcd7efd1fadb54e8 Mon Sep 17 00:00:00 2001 From: sarawone Date: Sun, 2 Aug 2026 11:35:47 +0100 Subject: [PATCH 9/9] exercise7 --- Perp-Exercise/exercise7.py | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Perp-Exercise/exercise7.py diff --git a/Perp-Exercise/exercise7.py b/Perp-Exercise/exercise7.py new file mode 100644 index 000000000..fa1c4262f --- /dev/null +++ b/Perp-Exercise/exercise7.py @@ -0,0 +1,42 @@ +from dataclasses import dataclass +from typing import List + +@dataclass(frozen=True) +class Person: + name: str + age: int + preferred_operating_systems: List[str] + + +@dataclass(frozen=True) +class Laptop: + id: int + manufacturer: str + model: str + screen_size_in_inches: float + operating_system: str + + +def find_possible_laptops(laptops: List[Laptop], person: Person) -> List[Laptop]: + possible_laptops = [] + for laptop in laptops: + if laptop.operating_system in person.preferred_operating_systems: + possible_laptops.append(laptop) + return possible_laptops + + +people = [ + Person(name="Imran", age=22, preferred_operating_systems=["Ubuntu","Arch Linux"]), + Person(name="Eliza", age=34, preferred_operating_systems=["Ubuntu","macOS"]), +] + +laptops = [ + Laptop(id=1, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system="Arch Linux"), + Laptop(id=2, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="Ubuntu"), + Laptop(id=3, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="ubuntu"), + Laptop(id=4, manufacturer="Apple", model="macBook", screen_size_in_inches=13, operating_system="macOS"), +] + +for person in people: + possible_laptops = find_possible_laptops(laptops, person) + print(f"Possible laptops for {person.name}: {possible_laptops}") \ No newline at end of file