-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdia14.py
More file actions
executable file
·96 lines (83 loc) · 2.55 KB
/
dia14.py
File metadata and controls
executable file
·96 lines (83 loc) · 2.55 KB
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
# gerenciador de tarefas
import os
import json
# funcao para carregar tarefas
def carregar_tarefas():
if os.path.exists('tarefas.json'):
with open('tarefas.json', 'r') as arquivo:
return json.load(arquivo)
return []
# exibe todas as tarefas
def listar_tarefas(tarefas):
print("Tarefas: ")
for tarefa in tarefas:
status = "Concluida" if tarefa['status'] else "Pendente"
print(f"ID: {tarefa['id']}, Título {tarefa['titulo']}, Status: {status}")
# escreve no arquivo e salva as tarefas
def salvar_tarefas(tarefas):
with open('tarefas.json', 'w') as arquivo:
json.dump(tarefas, arquivo, indent=4)
# gerar id
def gerar_id(tarefas):
if tarefas:
return tarefas[-1]['id'] + 1 # última tarefa com id 3, nova tarefa com id 4
# adicionar tarefas
def adicionar_tarefa(tarefas):
print("Adicionar nova tarefa")
titulo = input("Título: ")
descricao = input("Descrição: ")
tarefa = {
"id": gerar_id(tarefas),
"titulo": titulo,
"descricao": descricao,
"status": False
}
tarefas.append(tarefa)
salvar_tarefas(tarefas)
print("Tarefa inserida com sucesso!")
# concluir tarefa
def concluir_tarefa(tarefas):
try:
id_tarefa = int(input("Digite o ID da tarefa para concluir: "))
for tarefa in tarefas:
if tarefa['id'] == id_tarefa:
if tarefa['status']:
print("A tarefa já está concluída")
else:
tarefa['status'] = True
salvar_tarefas(tarefas)
print("Tarefa concluída com sucesso.")
return
print("Tarefa não encontrada")
except ValueError:
print("ID inválido.")
# menu principal
def menu():
print("=== GERENCIADOR DE TAREFAS ===")
print("1. Adicionar Tarefa")
print("2. Listar Tarefa")
print("3. Concluir Tarefa")
print("4. Remover Tarefa")
print("5. Sair")
return int(input("Escolha uma opção: "))
# Loop das ações
def main():
tarefas = carregar_tarefas()
while True:
opcao = menu()
if opcao == 1:
adicionar_tarefa(tarefas)
elif opcao == 2:
listar_tarefas(tarefas)
elif opcao == 3:
concluir_tarefa(tarefas)
elif opcao == 4:
excluir_tarefa(tarefas)
elif opcao == 5:
print("Encerrando programa...")
break
else:
print("Opção inválida.")
# inicialização da função main()
if __name__ == '__main__':
main()