-
Notifications
You must be signed in to change notification settings - Fork 8
/
05_czyste_funkcje.py
47 lines (32 loc) · 1007 Bytes
/
05_czyste_funkcje.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def silnia_czysta(n, wynik=1):
for i in range(1, n + 1):
wynik *= i
return wynik
def silnia_nieczysta(n, wynik=1):
for i in range(1, n + 1):
wynik *= i
with open("wynik.txt", "w") as f:
f.write(str(wynik))
return wynik
class Czlowiek:
def __init__(self, imie, wiek):
self.imie = imie
self.wiek = wiek
def __str__(self):
return f"{self.imie} ma {self.wiek} lat"
def __repr__(self):
return self.__str__()
def reset_czysta(czlowiek):
return Czlowiek(czlowiek.imie, 0)
def reset_nieczysta(czlowiek):
czlowiek.wiek = 0
return czlowiek
if __name__ == "__main__":
print(silnia_czysta(5))
print(silnia_nieczysta(5))
czlowiek = Czlowiek("Jan", 20)
print(f'Id czlowieka "{czlowiek}" to {id(czlowiek)}')
nowy_a = reset_czysta(czlowiek)
print(f'Id czlowieka "{nowy_a}" to {id(nowy_a)}')
nowy_b = reset_nieczysta(czlowiek)
print(f'Id czlowieka "{nowy_b}" to {id(nowy_b)}')