Skip to content

Commit 95f1e94

Browse files
committed
Added 1st, 2nd lessons
0 parents  commit 95f1e94

File tree

15 files changed

+471
-0
lines changed

15 files changed

+471
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Order
2+
1. Hello World! Introduction to Python. Variables and operators: numbers, strings, boolean type.
3+
hello_world.py, vars.py, boolean.py, types.py
4+
2. Conditional statements: if-elif-else, ternary operator. While loop.
5+
conditional_if.py, conditional_elif.py, while.py
6+
3. Lists. List operations.
7+
lists.py
8+
4. For loop. More lists. List comprehensions.
9+
for.py, more_lists.py, list_generators.py
10+
5. Dictionaries. Sets. Tuples.
11+
dicts_sets_tuples.py
12+
6. Functions. Lambdas. Decorators.
13+
functions.py
14+
7. Exceptions. Files. Context manager.
15+
exceptions.py, files.py
16+
8. Modules. Packages.
17+
modularity.py
18+
9. PEP 8 - code style. PEP 257 - documentation.
19+
Guido.md
20+
10. OOP basics in Python: classes.
21+
classes.py
22+
11. Abstraction. OOP principles: encapsulation, inheritance, polymorphism.
23+
encapsulation.py, inheritance.py, polymorphism.py
24+
12. Module abc. Static variables, methods. Properties.
25+
abstract.py, static.py, properties.py
26+
13. Python standard library: os, sys, re, math, random, datetime, timeit, doctest, unittest.
27+
oslib.py, syslib.py, relib.py, mathlib.py, randomlib.py, datetimelib.py, timeitlib.py, doctestlib.py, unittestlib.py
28+
14. PIP. Anaconda. Introduction to numpy, pandas, requests, bs4, flask.
29+
numpylib.py, pandaslib.py, requestslib.py, bs4lib.py, flaskr/start.sh
30+
15. Concurrency. GIL - Global Interpreter Lock. Modules threading and multiprocessing.
31+
threadinglib.py, prodcons.py, asynciolib.py, multiprocessinglib.py
32+
16. NLTK, Keras, scikit-learn. Introduction to Big Data.

boolean.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Запустить это - python boolean.py
2+
3+
apples = 2
4+
bananas = 4
5+
print("Apples:", apples)
6+
print("Bananas:", bananas)
7+
8+
# Считаем количество фруктов
9+
fruits = apples + bananas
10+
print("Fruits:", fruits)
11+
12+
# Фруктов больше 5?
13+
is_greater_than_five = (fruits > 5)
14+
print("Is greater than 5:", is_greater_than_five)
15+
16+
# Фруктов больше 8?
17+
is_greater_than_eight = (fruits > 8)
18+
print("Is greater than 8:", is_greater_than_eight)
19+
20+
# Boolean = True или False (истина или ложь, да или нет)
21+
22+
# Остальные операции над boolean
23+
x = 2
24+
y = 5
25+
print("x:", x)
26+
print("y:", y)
27+
print("x < 2", x < 2)
28+
print("x <= 2", x <= 2)
29+
print("y > 5", y > 5)
30+
print("y >= 5", y >= 5)
31+
print("x == 2", x == 2)
32+
print("y != 6", y != 6)
33+
34+
# Операция AND
35+
my_name = "Alex"
36+
my_age = 21
37+
print("Me:", my_name, my_age)
38+
39+
name = "Max"
40+
age = 24
41+
print("Someone:", name, age)
42+
43+
is_me = name == my_name and age == my_age
44+
print("Is it me:", is_me)
45+
46+
# X and Y = RESULT
47+
# T and T T
48+
# T and F F
49+
# F and T F
50+
# F and F F
51+
52+
# Операция OR
53+
color = "red"
54+
print("Color:", color)
55+
56+
is_blue_or_red = color == "blue" or color == "red"
57+
print("Is blue or red:", is_blue_or_red)
58+
59+
# X or Y = RESULT
60+
# T or T = T
61+
# T or F = T
62+
# F or T = T
63+
# F or F = F
64+
65+
# Операция NOT
66+
true_value = True
67+
false_value = not true_value
68+
print("True value:", true_value)
69+
print("False value:", false_value)
70+
71+
# not X = RESULT
72+
# not T = F
73+
# not F = T

conditional_elif.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Запустить это - python conditional_elif.py
2+
3+
# Оценка от 0 до 100 за тест
4+
mark = int(input('Please enter your mark: '))
5+
6+
# Условный переход
7+
if mark < 0: # условие №1
8+
print("Something is wrong. Must be higher than 0!") # если условие №1 истинно
9+
elif mark < 25: # условие №2
10+
print("It's a bad attempt. Try again!") # если условие №2 истинно
11+
elif mark >= 25 and mark < 50: # условие №3
12+
print("You can be better. Once again!") # если условие №3 истинно
13+
elif mark >= 50 and mark < 75: # условие №4
14+
print("Good enough. Maybe once again?") # если условие №4 истинно
15+
elif mark >= 75 and mark <= 100: # условие №5
16+
print("Good job! You are the best!") # если условие №5 истинно
17+
else:
18+
print("Something is wrong. Must be lower than 100!") # если никуда раньше не зашли
19+
20+
21+
22+
is_wrong = mark < 0 or mark > 100
23+
is_bad = mark < 25
24+
can_be_better = mark >= 25 and mark < 50
25+
is_good_enough = mark >= 50 and mark < 75
26+
is_good_job = mark >= 75 and mark <= 100
27+
28+
if is_wrong:
29+
print("Something is wrong. Must be higher than 0!")
30+
elif is_bad:
31+
print("It's a bad attempt. Try again!")
32+
elif can_be_better:
33+
print("You can be better. Once again!")
34+
elif is_good_enough:
35+
print("Good enough. Maybe once again?")
36+
elif is_good_job:
37+
print("Good job! You are the best!")

conditional_if.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Запустить это - python conditional_if.py
2+
3+
right_name = "Alex"
4+
right_password = "12345678"
5+
6+
name = input("Please enter the name: ")
7+
password = input("Please enter the password: ")
8+
9+
access_granted = "ACCESS GRANTED! You are in!"
10+
access_denied = "ACCESS DENIED! Wrong name or password!"
11+
12+
# Условный переход
13+
if name == right_name and password == right_password: # условие
14+
print(access_granted) # если условие истинно
15+
print('123')
16+
print(123)
17+
else:
18+
print(access_denied) # если условие ложно
19+
20+
21+
'''
22+
Это
23+
многострочный
24+
комментарий
25+
is_alex = name == right_name
26+
is_password_right = password == right_password
27+
can_login = is_alex and is_password_right
28+
if can_login:
29+
print(access_granted)
30+
else:
31+
print(access_denied)
32+
33+
print(access_granted if can_login else access_denied)
34+
'''

exercises/99bottles.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'''
2+
99 bottles of beer on the wall, 99 bottles of beer.
3+
Take one down and pass it around, 98 bottles of beer on the wall.
4+
...
5+
1 bottle of beer on the wall, 1 bottle of beer.
6+
Take one down and pass it around, no more bottles of beer on the wall.
7+
8+
No more bottles of beer on the wall, no more bottles of beer.
9+
Go to the store and buy some more, 99 bottles of beer on the wall.
10+
'''
11+
12+
bottles = 99
13+
14+
while bottles >= 0:
15+
if bottles == 1:
16+
print('1 bottle of beer on the wall, 1 bottle of beer.')
17+
print('Take one down and pass it around, no more bottles of beer on the wall.')
18+
elif bottles == 0:
19+
print('No more bottles of beer on the wall, no more bottles of beer.')
20+
print('Go to the store and buy some more, 99 bottles of beer on the wall.')
21+
else:
22+
bottle_string = str(bottles - 1) + (' bottles' if (bottles - 1) > 1 else ' bottle')
23+
print(f'{bottles} bottles of beer on the wall, {bottles} bottles of beer.')
24+
print(f'Take one down and pass it around, {bottle_string} of beer on the wall.')
25+
bottles -= 1
26+
27+
'''
28+
a = '{} bottles of beer'.format(bottles)
29+
b = '{ZZZ} bottles of beer'.format(ZZZ=bottles)
30+
c = f'{bottles} bottles of beer'
31+
print(a)
32+
print(b)
33+
print(c)
34+
'''
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+

exercises/lists.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'''
2+
Есть список с числами. Необходимо составить новый список, причем для каждого элемента этого списка вывести сумму двух его соседей.
3+
Для крайних элементов одним из соседей считается элемент с противоположного конца списка.
4+
Например:
5+
[1, 3, 5, 6, 10] -> [13, 6, 9, 15, 7]
6+
'''
7+
8+
l = [1, 3, 5, 6, 10]
9+
a = []
10+
11+
a.append(l[1] + l[-1])
12+
13+
for index in range(1, len(l) - 1):
14+
a.append(l[index - 1] + l[index + 1])
15+
16+
a.append(l[0] + l[-2])
17+
18+
print(a)

exercises/seasons.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'''
2+
Переменная month содержит номер месяца
3+
Нужно вывести время года, которому принадлежит месяц
4+
'''
5+
6+
month = int(input('Month: '))
7+
8+
if month == 12 or 1 <= month <= 2:
9+
print('Winter')
10+
elif 3 <= month <= 5: # 3 <= month <= 5
11+
print('Spring')
12+
elif 6 <= month <= 8:
13+
print('Summer')
14+
elif 9 <= month <= 11:
15+
print('Autumn')
16+
else:
17+
print('Error')

exercises/sum_all_even.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'''
2+
Суммировать все четные числа от 0 до n
3+
'''
4+
5+
n = int(input('Enter number: '))
6+
counter = 0
7+
accumulator = 0
8+
9+
while counter != n:
10+
if counter % 2 == 0:
11+
accumulator += counter
12+
counter += 1 # counter = counter + 1
13+
14+
print(accumulator)

exercises/tutor/lists.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'''
2+
Есть список с числами. Необходимо составить новый список, причем для каждого элемента этого списка вывести сумму двух его соседей. Для крайних элементов одним из соседей считается элемент с противоположного конца списка.
3+
Например:
4+
[1, 3, 5, 6, 10] -> [13, 6, 9, 15, 7]
5+
'''
6+
7+
a = [1, 3, 5, 6, 10]
8+
b = []
9+
10+
for index in range(len(a)):
11+
if index == 0:
12+
value = a[index + 1] + a[-1]
13+
elif index == len(a) - 1:
14+
value = a[index - 1] + a[0]
15+
else:
16+
value = a[index - 1] + a[index + 1]
17+
b.append(value)
18+
19+
'''
20+
b = []
21+
for index in range(len(a)):
22+
previous_index = (index - 1)
23+
next_index = (index + 1) % len(a)
24+
value = a[previous_index] + a[next_index]
25+
b.append(value)
26+
'''
27+
28+
print(b)

for.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Запустить это - python for.py
2+
3+
# Списки
4+
list_of_numbers = [1, 2, 3]
5+
list_of_strings = ["Hello", " ", "World", "!"]
6+
list_of_mixed_types = [1, "apple", 2, 4.5, False]
7+
8+
# Вывести элементы списка
9+
print("Elements of list of mixed types:")
10+
for element in list_of_mixed_types:
11+
print(element)
12+
13+
# Сложить все числа в списке
14+
print("Sum of all numbers in list of numbers:")
15+
accumulator = 0
16+
for element in list_of_numbers:
17+
accumulator += element
18+
print(accumulator)
19+
20+
# Конкатенировать все строки в списке
21+
print("Concatenate all strings in list of strings:")
22+
accumulator = ""
23+
for element in list_of_strings:
24+
accumulator += element
25+
print(accumulator)
26+
27+
# Как я говорил, строки = списки символов
28+
print("Letters:")
29+
for letter in "Alex":
30+
print(letter)

0 commit comments

Comments
 (0)