Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54b982f637 | ||
|
|
41c0c31f97 | ||
|
|
d73e6cb2ec |
No files matched your search
@@ -0,0 +1,18 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v4.5.0
|
||||||
|
hooks:
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: check-yaml
|
||||||
|
- id: check-added-large-files
|
||||||
|
|
||||||
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
|
rev: v0.3.0
|
||||||
|
hooks:
|
||||||
|
- id: ruff # Linting
|
||||||
|
|
||||||
|
- repo: https://github.com/psf/black
|
||||||
|
rev: stable
|
||||||
|
hooks:
|
||||||
|
- id: black # formatting
|
||||||
Whitespace-only changes.
@@ -0,0 +1,32 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class Konto:
|
||||||
|
inhaber: str
|
||||||
|
saldo: float
|
||||||
|
|
||||||
|
def __init__(self, inhaber: str, saldo: float):
|
||||||
|
if not inhaber:
|
||||||
|
raise ValueError("inhaber is required")
|
||||||
|
if saldo < 0:
|
||||||
|
raise ValueError("saldo must be positive")
|
||||||
|
object.__setattr__(self, "inhaber", inhaber)
|
||||||
|
object.__setattr__(self, "saldo", saldo)
|
||||||
|
|
||||||
|
def einzahlen(self, betrag: float):
|
||||||
|
object.__setattr__(self, "saldo", self.saldo + betrag)
|
||||||
|
|
||||||
|
def abheben(self, betrag: float):
|
||||||
|
object.__setattr__(self, "saldo", self.saldo - betrag)
|
||||||
|
return betrag
|
||||||
|
|
||||||
|
|
||||||
|
k1 = Konto("Alice", 100.0)
|
||||||
|
k2 = Konto("Housi", 10)
|
||||||
|
k2.einzahlen(100)
|
||||||
|
|
||||||
|
print(k1.inhaber)
|
||||||
|
print(k2.saldo)
|
||||||
|
print(k1 is k2)
|
||||||
|
print(k1)
|
||||||
Whitespace-only changes.
@@ -0,0 +1,9 @@
|
|||||||
|
def last_digit(lst):
|
||||||
|
rev_lst = list(reversed(lst))
|
||||||
|
|
||||||
|
n = 1
|
||||||
|
|
||||||
|
for number in rev_lst:
|
||||||
|
n = number ** (n if n < 4 else n % 4 + 4)
|
||||||
|
|
||||||
|
return n % 10
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
class Dog:
|
||||||
|
amount_of_dogs = 0
|
||||||
|
name: str
|
||||||
|
race: str
|
||||||
|
age: int
|
||||||
|
weight: float
|
||||||
|
bark_sound: str
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, name: str, race: str, age: int, weight: float, bark_sound: str
|
||||||
|
) -> None:
|
||||||
|
self.name = name
|
||||||
|
self.race = race
|
||||||
|
self.age = age
|
||||||
|
self.weight = weight
|
||||||
|
self.bark_sound = bark_sound
|
||||||
|
|
||||||
|
Dog.amount_of_dogs += 1
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.name} is a {self.age} year old {self.race}"
|
||||||
|
|
||||||
|
def bark(self, times: int = 1) -> str:
|
||||||
|
return f"{self.name} says:" + (f" {self.bark_sound}" * times)
|
||||||
|
|
||||||
|
def birthday(self) -> str:
|
||||||
|
self.age += 1
|
||||||
|
return f"Happy Birthday, {self.name}! You're now {self.age} years old!"
|
||||||
|
|
||||||
|
def is_puppy(self) -> bool:
|
||||||
|
return self.age < 2
|
||||||
|
|
||||||
|
|
||||||
|
class Shepperd(Dog):
|
||||||
|
race: str = "shepperd"
|
||||||
|
bark_sound: str = "Woo!"
|
||||||
|
|
||||||
|
def __init__(self, name: str, age: int, weight: float) -> None:
|
||||||
|
Dog.__init__(self, name, Shepperd.race, age, weight, Shepperd.bark_sound)
|
||||||
|
|
||||||
|
|
||||||
|
class Poodle(Dog):
|
||||||
|
race: str = "poodle"
|
||||||
|
bark_sound: str = "Wow!"
|
||||||
|
|
||||||
|
def __init__(self, name: str, age: int, weight: float) -> None:
|
||||||
|
Dog.__init__(self, name, Poodle.race, age, weight, Poodle.bark_sound)
|
||||||
|
|
||||||
|
|
||||||
|
dog1 = Shepperd("Bello", 5, 22.5)
|
||||||
|
print(dog1)
|
||||||
|
print(dog1.bark())
|
||||||
|
print(dog1.birthday())
|
||||||
|
print(Dog.amount_of_dogs)
|
||||||
|
|
||||||
|
dog2 = Poodle("Barky", 10, 20)
|
||||||
|
print(dog2.bark(3))
|
||||||
|
print(dog2.is_puppy())
|
||||||
|
print(Dog.amount_of_dogs)
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
def addition(a=1, b=2):
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
|
||||||
|
def f(x: int, y: int) -> int:
|
||||||
|
return x + y
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(addition(5, 5))
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
from codewars.lastDigitOfHugeNumber import last_digit
|
||||||
|
|
||||||
|
|
||||||
|
def test_last_digit():
|
||||||
|
test_data = [
|
||||||
|
([], 1),
|
||||||
|
([0, 0], 1),
|
||||||
|
([0, 0, 0], 0),
|
||||||
|
([1, 2], 1),
|
||||||
|
([3, 4, 5], 1),
|
||||||
|
([4, 3, 6], 4),
|
||||||
|
([7, 6, 21], 1),
|
||||||
|
([12, 30, 21], 6),
|
||||||
|
([2, 2, 2, 0], 4),
|
||||||
|
([937640, 767456, 981242], 0),
|
||||||
|
([123232, 694022, 140249], 6),
|
||||||
|
([499942, 898102, 846073], 6),
|
||||||
|
]
|
||||||
|
for test_input, test_output in test_data:
|
||||||
|
assert last_digit(test_input) == test_output
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from src.moduleA import addition
|
||||||
|
|
||||||
|
|
||||||
|
def test_a():
|
||||||
|
assert addition() == 3
|
||||||
|
assert addition(5, 5) == 10
|
||||||
Reference in new issue
Block a user