diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c1cb9df --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ + + { + "python.linting.enabled": true, + "python.linting.mypyEnabled": true, + "python.linting.mypyArgs": ["--ignore-missing-imports"], + "python.analysis.typeCheckingMode": "basic" + } diff --git a/AYK/class&object.py b/AYK/class&object.py new file mode 100644 index 0000000..c774bba --- /dev/null +++ b/AYK/class&object.py @@ -0,0 +1,21 @@ +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) + +eliza = Person("Eliza", 34, "Arch Linux") +print(eliza.name) + + +def is_adult (person: Person) ->bool: + return person.age >=18 + +print(is_adult(imran)) + +def current_address (address : Person): + return address.location; + diff --git a/AYK/typechecking_mypy.py b/AYK/typechecking_mypy.py new file mode 100644 index 0000000..c407442 --- /dev/null +++ b/AYK/typechecking_mypy.py @@ -0,0 +1,30 @@ +def open_account(balances, name, amount): + balances[name] = amount + +def sum_balances(accounts): + 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): + if total_pence < 100: + return f"{total_pence}p" + pounds = int(total_pence / 100) + pence = total_pence % 100 + return f"£{pounds}.{pence:02d}" + +balances = { + "Sima": 700, + "Linn": 545, + "Georg": 831, +} + +open_account(balances,"Tobi", 9.13) +open_account(balances,"Olya", "£7.13") + +total_pence = sum_balances(balances) +total_string = format_pence_as_string(total_pence) + +print(f"The bank accounts total {total_string}") \ No newline at end of file diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..323ce15 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,5 @@ +python_version = 3.9.6 +warn_return_any = True +warn_unused_configs = True +disallow_untyped_defs = True +ignore_missing_imports = True \ No newline at end of file