Skip to content

Commit 68fe0ec

Browse files
Aktualizacja
1 parent 475339e commit 68fe0ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+459
-170
lines changed

02_Hello_World/script_with_main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
if __name__ == '__main__':
2-
print('Hello World from main')
2+
print('Hello World from main')

03_Zmienne_i_typy_danych/konwersje_i_typizacja.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
a = "3"
55

6-
a = a+3 # Bład !!!!
6+
a = a+3 # Bład !!!!
77

88
a = int("3")
99

03_Zmienne_i_typy_danych/wartosci.py

+7
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@
77
(2 + 2) * 2
88

99
50 - 5*6
10+
11+
7%2
12+
13+
'''
14+
Ala
15+
ma kota
16+
'''

03_Zmienne_i_typy_danych/zmienne.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
a=2+2
2-
A=5
1+
a = 2 + 2
2+
A = 5
33
print(a)
44
print(A)
55

6-
a += 2
6+
a += 2 # a = a + 2
77
a
8-
a *= 0
8+
a *= 0 # a = a * 0
99
a
10-

04_Instrukcje_warunkowe/if.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
a = 3
1+
a = 4
22

33
# IF
44
if a == 3:
55
print("Then shalt thou count to three, no more, no less.")
66
print("Three shall be the number thou shalt count, and the number of the counting shall be three.")
77
print("Four shalt thou not count, neither count thou two, excepting that thou then proceed to three. ")
8+
else:
9+
print('Not three')
10+
11+
if a == 3:
12+
print("three")
13+
else:
14+
if a == 4:
15+
print("four")
16+
else:
17+
print('Not three or four')
18+
819

920
n = int(input('Podaj liczbę'))
1021
print(n)
@@ -28,16 +39,15 @@
2839
if (n == 17) or not (n == 17):
2940
print("Tertium non datur")
3041
print("Innej opcji nie ma")
42+
n = 5
43+
if n == 17 or n != 17:
44+
print("Tertium non datur")
45+
print("Innej opcji nie ma")
3146

3247
# := "Walrus" operator
3348
if (i := int(input("podaj liczbę naturalną"))) % 2 == 0:
3449
print(f'{i} jest parzyste')
3550
else:
3651
print(f'{i} jest nieparzyste')
3752

38-
i = int(input("podaj liczbę naturalną"))
39-
suma_cyfr = (i % 10 + i // 10)
40-
if (suma_cyfr % 7 == 0) and (i % 2 == 0):
41-
print(f'Dobra liczba')
42-
else:
43-
print(f'Zła liczba')
53+

05_Petle/input.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
n = int(input("Podaj liczbę:"))
22
print(f'Podałeś liczbę {n}')
3+

05_Petle/while.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
if n % 2 == 0:
1111
print(f'{n} tik')
1212
continue
13-
1413
print(f'{n} tak')
1514

15+
1616
n = 8
1717
while n > 0:
1818
n -= 1

06_Lancuchy_znakow/arytmetyka.py

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
s == "Ala"
1919

2020
"10" < "2"
21+
10 < 2

07_Listy/listy.py

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
l
3535
l.pop()
3636
l
37+
l.index('A')
3738

3839
" - ".join(["Ala", "ma", "kota"])
3940
"".join(["Ala", "ma", "kota"])
@@ -42,3 +43,7 @@
4243
s2.join(["Ala", "ma", "kota"])
4344

4445
'.' in s2
46+
47+
3 in l
48+
49+
l.insert(2, 100)

08_Krotki/krotki.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
t[1]
44
t = 1, 2, 3, 4
55
t
6-
t[1] = 19 # Błąd
6+
t[1] = 19 # Błąd
77

88
t = tuple(range(5))
99
t
1010
t = tuple([1, 2, 3, 4])
11-
t
11+
t
12+
13+
a = 3
14+
b = 5
15+
a, b
16+
b, a = a, b

11_Listy_i_zbiory-zaawansowane_mechanizmy/iteratory_generatory.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def fib(n):
4545
for i in range(35):
4646
print("n=%d => %d" % (i, fib(i)))
4747

48-
4948
def fib(n):
5049
a, b = 0, 1
5150
i = 0
@@ -57,3 +56,7 @@ def fib(n):
5756

5857
for i, f in fib(35):
5958
print("n=%d => %d" % (i, f))
59+
60+
data = {"Sedan": 1500, "SUV": 2000, "Pickup": 2500, "Minivan": 1600, "Van": 2400, "Semi": 13600, "Bicycle": 7,
61+
"Motorcycle": 110}
62+
[x.upper() for x in data.keys() if data[x] > 5000]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
numbers = list(range(1,11))
2+
letters = [chr(i) for i in range(ord('A'), ord('A')+10)]
3+
4+
print(numbers)
5+
print(letters)
6+
7+
print(zip(letters, numbers))
8+
9+
print(list(zip(letters, numbers)))
10+
11+
slownik = dict(x=4, z=8)
12+
print(slownik)
13+
slownik = dict({'x': 4, 'y': 5}, z=8)
14+
print(slownik)
15+
slownik = dict([('x', 4), ('y', 5)])
16+
print(slownik)
17+
slownik = dict(zip(letters, numbers))
18+
print(slownik)

12_Wyjatki_i_obsluga_bledow/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 12. Wyjątki i obsługa błędów
22

33
- Rodzaje błędów
4-
- Programistyczne - te eleminujemy poprawiając kod
4+
- Programistyczne - te eliminujemy poprawiając kod
55
- Infrastruktury - nie naprawimy, ale przynajmniej komunikujemy
66
- Błedne dane - tu trzeba to obsłużyć - podając np. źródło błędu
77

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22

3-
def function_with_error():
3+
def function_with_error(i):
44
l = [0]
5-
return l[6]
5+
return l[i]
66

77

88
def ok_function():
9-
return function_with_error()
9+
return function_with_error(6)
1010

12_Wyjatki_i_obsluga_bledow/wyjatek.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22
print(l)
33
try:
44
i = int(input("podaj indeks "))
5-
print(f'Pod indeksem {i} jest element {l[i]}')
5+
print(f'Pod indeksem {i} jest element {l[i]}') # Komentarz
6+
7+
# Bardzo złozona operacja sprzatania
8+
69
except IndexError as e:
710
print(e)
11+
except ValueError as e:
12+
print("In Value Error")
13+
print(e)
14+
except Exception as e:
15+
print("In Exception")
16+
print(e)
817
else:
918
print("Koniec")
1019
finally:

13_Funkcje/args.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
print(1, 2 , 6, 5)
1+
print(1, 2, 6, 5)
22

33

44
def test_var_args(farg, *args):
5-
print ("formal arg:", farg)
5+
print("formal arg:", farg)
66
print(args)
77
for arg in args:
88
print ("another arg:", arg)

13_Funkcje/first_class_citizen.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def noop_log(message):
77

88

99
def get_log(mode):
10-
s = {'dev': print_log}
10+
s = {'dev': print_log, 'prod': noop_log}
1111
return s.get(mode, noop_log)
1212

1313
env_mode = "dev"

13_Funkcje/przyklad.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ def choinka(poziom, separator=" ", znak="*"):
7070

7171

7272
choinka(5)
73-
choinka(znak='#', poziom=6)
73+
choinka(poziom=5, separator="$")

13_Funkcje/slownie.py

-9
This file was deleted.

14_Moduly/fib_module.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ def fib(n): # return Fibonacci series up to n
1313

1414

1515
if __name__ == '__main__':
16-
print(f'Testowo: {fib(5)}')
16+
print(f'Testowo: {fib(15)}')

14_Moduly/fib_package.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
if __name__ == '__main__':
55
print(sys.path) # Tu szukamy modułów
66
print(f1.fib(25))
7+

14_Moduly/fib_script.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
n = int(sys.argv[1])
66
print(f'Pierwsze {n} liczb Fibonacciego')
77
print(fib_module.fib(n))
8+
print(fib_module.__name__)
9+

14_Moduly/import_module.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from fib_module import fib
2+
3+
print(fib(100))

15_Pliki_tekstowe/plik.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello

16_Dane_zdalne/countries.py

-22
This file was deleted.

17_Wykorzystanie_baz_danych/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929

3030
# Zadania
3131
- Załadować do bazy danych postgres pythonem zawartość pliku `foods.csv`
32-
- Załądować do bazy danych sqllite pythonem zawartość pliku `foods.csv` korzystając z SQLa
33-
- Załądować do bazy danych sqllite pythonem zawartość pliku `foods.csv` korzystając z SQL Alchemy
32+
- Załadować do bazy danych sqllite pythonem zawartość pliku `foods.csv` korzystając z SQLa
33+
- Załadować do bazy danych sqllite pythonem zawartość pliku `foods.csv` korzystając z SQL Alchemy

17_Wykorzystanie_baz_danych/postgres.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import psycopg2
22

3-
connect_string = "dbname=my_database user=user password=secret host=127.0.0.1"
3+
connect_string = "dbname=my_database user=my_user password=secret host=127.0.0.1"
44

55
with psycopg2.connect(connect_string) as connection:
66
try:

17_Wykorzystanie_baz_danych/sqlalchemy4-relationships.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
from sqlalchemy.orm import relationship
77

8-
98
warnings.filterwarnings("ignore")
109

1110
engine = sa.create_engine('sqlite:///:memory:')
1211
Base = declarative_base()
1312
session = sa.orm.sessionmaker(bind=engine)()
1413

14+
1515
class OrderItem(Base):
1616
__tablename__ = 'order'
1717

@@ -20,12 +20,14 @@ class OrderItem(Base):
2020
user_id = sa.Column('user_id', sa.Integer, sa.ForeignKey('user.id'))
2121
qty = sa.Column('qty', sa.Integer)
2222

23+
2324
class Product(Base):
2425
__tablename__ = 'product'
2526

2627
id = sa.Column('id', sa.Integer, primary_key=True)
2728
name = sa.Column('name', sa.Text)
28-
price = sa.Column('price', sa.Numeric(14,2))
29+
price = sa.Column('price', sa.Numeric(14, 2))
30+
2931

3032
class User(Base):
3133
__tablename__ = 'user'
@@ -35,10 +37,11 @@ class User(Base):
3537
last_name = sa.Column('last_name', sa.Text)
3638

3739
products = relationship("Product",
38-
secondary='order',
39-
uselist=True,
40-
backref='users',
41-
lazy='select')
40+
secondary='order',
41+
uselist=True,
42+
backref='users',
43+
lazy='select')
44+
4245

4346
Base.metadata.create_all(engine)
4447

@@ -61,4 +64,4 @@ class User(Base):
6164
rabbit = john.products[0]
6265
len(rabbit.users)
6366
for u in rabbit.users:
64-
print(u.last_name)
67+
print(u.last_name)

17_Wykorzystanie_baz_danych/sqllite.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
cur.execute("CREATE TABLE movie(title, year, score)")
66

77
res = cur.execute("SELECT name FROM sqlite_master")
8-
res.fetchone()
8+
print (res.fetchone())
99

1010
res = cur.execute("SELECT name FROM sqlite_master WHERE name='spam'")
1111
res.fetchone()

0 commit comments

Comments
 (0)