This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lesson2.py
136 lines (112 loc) · 5.35 KB
/
lesson2.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import typing
def original_function():
HELP = """
help - напечатать справку по программе.
add - добавить задачу в список (название задачи запрашиваем у пользователя).
show - напечатать все добавленные задачи."""
tasks = []
run = True
while run:
command = input("Введите команду: ")
if command == "help":
print(HELP)
elif command == "show":
print(tasks)
elif command == "add":
task = input("Введите название задачи: ")
tasks.append(task)
print("Задача добавлена")
else:
print("Неизвестная команда")
break
print("До свидания!")
def task1() -> None:
"""Модифицируйте программу, написанную на занятии так, чтобы выход из
нее осуществлялся не только при вводе неизвестной команды, но и при вводе
специальной команды exit. Сделайте так, чтобы при вводе этой команды
программа выводила на экран текст: "Спасибо за использование!
До свидания!"
"""
HELP: typing.Final[str] = "\n".join(
[
"\thelp - напечатать справку по программе.",
(
"\tadd - добавить задачу в список (название задачи "
"запрашиваем у пользователя)."
),
"\tshow - напечатать все добавленные задачи.",
"\texit - завершить работу программы",
]
)
tasks: typing.List[str] = []
while True:
command = input("Введите команду: ")
if command == "help":
print(HELP)
elif command == "show":
print(tasks)
elif command == "add":
task = input("Введите название задачи: ")
tasks.append(task)
print("Задача добавлена")
elif command == "exit":
print("Спасибо за использование! ", end="")
break
else:
print("Неизвестная команда")
break
print("До свидания!")
def task2() -> None:
"""Сделайте следующие изменения:
Заведите 3 списка: today, tomorrow, other (вы можете назвать переменные
по-другому).
Измените блок кода, который выполняет команду add:
Дополнительно запросите у пользователя дату выполнения задачи.
В зависимости от введенной даты добавьте задачу в один из списков по
следующим правилам:
Если пользователь ввел "Сегодня", добавьте задачу в список today.
Если пользователь ввел "Завтра", добавьте задачу в список tomorrow.
Если пользователь ввел любое другое значение, добавьте задачу в
список other.
"""
HELP: typing.Final[str] = "\n".join(
[
"\thelp - напечатать справку по программе.",
(
"\tadd - добавить задачу в список (название задачи и время "
"ее выполнения запрашиваем у пользователя)."
),
"\tshow - напечатать все добавленные задачи.",
"\texit - завершить работу программы",
]
)
default_tasks_date: typing.Final[str] = "другое время"
tasks: typing.Dict[str, typing.List[str]] = {
"сегодня": [],
"завтра": [],
default_tasks_date: [],
}
while True:
command = input("Введите команду: ")
if command == "help":
print(HELP)
elif command == "show":
for tasks_date, tasks_list in tasks.items():
print(f'Задачи на {tasks_date}: {", ".join(tasks_list)}')
elif command == "add":
task = input("Введите название задачи: ")
date = input("Введите дату выполнения задачи: ")
tasks.get(date.lower(), tasks[default_tasks_date]).append(task)
print("Задача добавлена")
elif command == "exit":
print("Спасибо за использование! ", end="")
break
else:
print("Неизвестная команда")
break
print("До свидания!")
if __name__ == "__main__":
print("======== Задание 1 ========")
task1()
print("======== Задание 2 ========")
task2()