Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 2 #1801

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
4 changes: 4 additions & 0 deletions Урок 2. Практическое задание/task_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
<class 'bool'>
<class 'NoneType'>
"""

lst = [423, "second", 453.43, False, None, [12, 23]]
for i in range(len(lst)):
print(type(lst[i]))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно проще
for el in lst:
print(type(el))

7 changes: 7 additions & 0 deletions Урок 2. Практическое задание/task_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@
Введите целые числа через пробел: 1 2 3
Результат: 2 1 3
"""

lst = [int(i) for i in input("Введите целые числа через пробел: ").split()]
for i in range(len(lst) // 2):
lst[i * 2] = lst[i * 2] + lst[i * 2 + 1]
lst[i * 2 + 1] = lst[i * 2] - lst[i * 2 + 1]
lst[i * 2] = lst[i * 2] - lst[i * 2 + 1]
print(lst)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выполнено

7 changes: 7 additions & 0 deletions Урок 2. Практическое задание/task_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@
Результат через список: Осень
Результат через словарь: Осень
"""

dct = {1: 'Зима', 2: 'Зима', 3: "Весна", 4: 'Весна', 5: 'Весна', 6: 'Лето', 7: 'Лето', 8: 'Лето', 9: 'Осень',
10: 'Осень', 11: 'Осень', 12: 'Зима'}
lst = ['', 'Зима', 'Зима', "Весна", 'Весна', 'Весна', 'Лето', 'Лето', 'Лето', 'Осень', 'Осень', 'Осень', 'Зима']
month_number = int(input("Введите номер месяца: "))
print(dct[month_number])
print(lst[month_number])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'',
?? для чего

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

month = int(input("Введите номер месяца: "))

my_lst = [
"Зима",
"Зима",
"Весна",
"Весна",
"Весна",
"Лето",
"Лето",
"Лето",
"Осень",
"Осень",
"Осень",
"Зима"]

print(f'Результат через список: {my_lst[month - 1]}')

my_dict = {1: "Зима", 2: "Зима", 3: "Весна", 4: "Весна", 5: "Весна",
6: "Лето", 7: "Лето", 8: "Лето", 9: "Осень", 10: "Осень",
11: "Осень", 12: "Зима"}

print(f'Результат через словарь: {my_dict.get(month)}')

5 changes: 5 additions & 0 deletions Урок 2. Практическое задание/task_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@
1. раз
2. перерефриж
"""

prompt = 0
for i in input("Введите слова через пробел: ").split():
prompt += 1
print(f"{prompt}. {i[:10]}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь нужна ф-ция enumerate

11 changes: 11 additions & 0 deletions Урок 2. Практическое задание/task_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@
Набор натуральных чисел можно задать непосредственно в коде,
например, my_list = [7, 5, 3, 3, 2].
"""

my_list = [7, 5, 3, 3, 2]
new_number = int(input("Введите натуральное число "))
if my_list[len(my_list) - 1] > new_number:
my_list.append(new_number)
else:
for i in range(len(my_list)):
if my_list[i] < new_number:
my_list.insert(i, new_number)
break
print(my_list)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выполнено

26 changes: 26 additions & 0 deletions Урок 2. Практическое задание/task_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,29 @@
“ед”: [“шт.”]
}
"""

i = 1
keep = True
lst = []
while keep:
lst.append((i, {"название": input("Введите название товара: "),
"цена": int(input("Введите цену товара: ")),
"количество": int(input("Введите количество товара: ")),
"ед": input("Введите единицу измерения товара: ")}))
i += 1
keep = input("Введите 'y' для продолжения ввода или любой другой символ для прекращения ввода: ") == "y"

result = {"названия": set(), "цены": set(), "количества": set(), "ед": set()}

for _, value in lst:
result["названия"].add(value["название"])
result["цены"].add(value["цена"])
result["количества"].add(value["количество"])
result["ед"].add(value["ед"])

print('{')
print(f'"названия": {list(result["названия"])},'.replace("'", '"'))
print(f'"цены": {list(result["цены"])},')
print(f'"количества": {list(result["количества"])},')
print(f'"ед": {list(result["ед"])}'.replace("'", '"'))
print('}')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выполнено