-
Notifications
You must be signed in to change notification settings - Fork 337
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
base: master
Are you sure you want to change the base?
Lesson 2 #1801
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. выполнено |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. '', There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: "Весна", print(f'Результат через словарь: {my_dict.get(month)}') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,8 @@ | |
1. раз | ||
2. перерефриж | ||
""" | ||
|
||
prompt = 0 | ||
for i in input("Введите слова через пробел: ").split(): | ||
prompt += 1 | ||
print(f"{prompt}. {i[:10]}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. здесь нужна ф-ция enumerate |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. выполнено |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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('}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. выполнено |
There was a problem hiding this comment.
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))