Skip to content

Commit e0573ca

Browse files
CHALLENGE 115 - STARTED AND COMPLETED 100%
1 parent 5ebbbde commit e0573ca

File tree

2 files changed

+86
-59
lines changed

2 files changed

+86
-59
lines changed

MiniSystem/system/__init__.py

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
# def lists():
2+
from MiniSystem.system import *
3+
from MiniSystem.arquivo import *
24
people = {"Johnny Gabriel": 26, "Jorge Marcelino": 30, "Maria de Fatima": 67, "Clelia Pereira": 61, "Almir Aguiar": 34,
35
"Cleiton Aguiar": 36, "Jéssica Lira": 29, "Lucas Cauan": 9, "Daniel Caique": 8}
46
# return people
57
# "Marcelo da Costa": 35
8+
arq = "FileSystem.txt"
9+
10+
611

712
def menu(msg = "PRINCIPAL MENU"):
813
a = "=" * 50
914
# msg = "MENU PRINCIPAL"
10-
c = a.count("=") # conta quantas vezes aparece sinal '='
15+
# c = a.count("=") # conta quantas vezes aparece sinal '='
1116
print(a)
12-
c = c / 2
13-
d = c // 1.5
14-
d = int(d)
15-
print(' ' * (d), f'{msg}', ' ' * (d))
17+
# c = c / 2
18+
# d = c // 1.5
19+
# d = int(d)
20+
# print(' ' * (d), f'{msg.center()}', ' ' * (d))
21+
print(f'{msg.center(50)}')
1622
print(a)
1723
option()
1824

@@ -38,57 +44,32 @@ def option():
3844
print("\033[0;34m3 - Quit of the system\033[m")
3945
print("=" * 50)
4046
choice = int(input("Your option: "))
41-
# if(type(choice) != int(choice)):
42-
# while(type(choice) != int(choice)):
43-
# choice = int(input("Your option: "))
44-
# if(choice.isnumeric()):
45-
# choice = int(choice)
46-
# else:
47-
# while(choice is not choice.isdigit()):
48-
# print("=" * 50)
49-
# print("\033[0;31mERROR!\033[m")
50-
# print(
51-
# "\033[0;34mType only:\n1 - See people's list\n2 - Registry new person or\n3 - Quit of the system\033[m")
52-
# choice = input("Your option: ")
53-
# print("=" * 50)
5447
except:
55-
print("=" * 50)
56-
print("\033[0;31mERROR!\033[m")
57-
print("\033[0;34mType only:\033[m")
58-
# print(
59-
# "\033[0;34mType only:\n1 - See people's list\n2 - Registry new person or\n3 - Quit of the system\033[m")
60-
# choice = int(input("Your option: "))
61-
continue
62-
# choice = input("Your option: ")
63-
# while(choice.isnumeric() != int(choice)):
64-
# print("=" * 50)
65-
# print("\033[0;31mERROR!\033[m")
66-
# print("\033[0;34mType only:\n1 - See people's list\n2 - Registry new person or\n3 - Quit of the system\033[m")
67-
# choice = int(input("Your option: "))
68-
else:
69-
while(choice > 3 or choice < 0):
7048
print("=" * 50)
7149
print("\033[0;31mERROR!\033[m")
72-
print("\033[0;34mType only:\n1 - See people's list\n2 - Registry new person or\n3 - Quit of the system\033[m")
73-
choice = int(input("Your option: "))
74-
print("=" * 50)
75-
# menu("="*30)
76-
if (choice == 1):
77-
seePeop()
78-
elif (choice == 2):
79-
newReg("NEW REGISTRY")
80-
else:
81-
if(choice == 3):
82-
from time import sleep
83-
sleep(2)
84-
print("Logging out of the System so far!")
85-
# else:
86-
# while (choice > 3 or choice < 0):
87-
# print("\033[0;31mERROR!\033[m")
88-
# print(
89-
# "\033[0;33mType only:\n1 - See people's list\n2 - Registry new person or\n3 - Quit of the system\033[m")
90-
# choice = int(input("Your option: "))
91-
# Error Handling
50+
print("\033[0;34mType only:\033[m")
51+
continue
52+
else:
53+
if(choice > 3 or choice < 0):
54+
while(choice > 3 or choice < 0):
55+
print("=" * 50)
56+
print("\033[0;31mERROR!\033[m")
57+
print("\033[0;34mType only:\n1 - See people's list\n2 - Registry new person or\n3 - Quit of the system\033[m")
58+
choice = int(input("Your option: "))
59+
break
60+
if (choice == 1):
61+
readFile(arq)
62+
break
63+
elif (choice == 2):
64+
newReg("NEW REGISTRY")
65+
else:
66+
if(choice == 3):
67+
from time import sleep
68+
sleep(2)
69+
print("Logging out of the System so far!")
70+
break
71+
break
72+
break
9273

9374

9475
def seePeop():
@@ -109,11 +90,48 @@ def regPeop():
10990
age = input("Age: ")
11091
while(age.isnumeric() != True):
11192
age = input("Age: ")
112-
people[name] = age
113-
# for last in people.values():
114-
# if(last == name)
93+
a = open(arq, "at")
94+
a.write(f"{name};{age}\n")
95+
# arq[name] = age
11596
print(f"New registry noted of {name} added")
97+
a.close()
11698
menu("PRINCIPAL MENU")
11799

118-
# menu("PRINCIPAL MENU")
119-
# option()
100+
101+
def filExist(nome):
102+
try:
103+
a = open(nome, "rt")
104+
a.close()
105+
except FileNotFoundError:
106+
return False
107+
else:
108+
return True
109+
110+
111+
112+
def creatFile(nome):
113+
try:
114+
a = open(nome, "wt+")
115+
a.close()
116+
except:
117+
print("There is some problem with the create the file")
118+
else:
119+
print(f"File {nome}, created with success!")
120+
readFile(arq)
121+
122+
123+
def readFile(name):
124+
try:
125+
a = open(name, "rt")
126+
except:
127+
print("There is a problem with the program")
128+
else:
129+
# menu("List of People")
130+
print("List of People")
131+
for linhas in a:
132+
dado = linhas.split(";")
133+
dado[1] = dado[1].replace("\n", "")
134+
print(f"{dado[0]:<30}{dado[1]:>3} anos")
135+
print(a.read())
136+
finally:
137+
option()

Mundo-03.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,15 @@ def leiaFloat(msg):
23092309
# CHALLENGE 115
23102310
# Vamos criar um menu em Python, usando modularização.
23112311

2312+
from MiniSystem.arquivo import *
2313+
from MiniSystem.system import *
23122314
from MiniSystem import system
23132315

2314-
system.menu()
2316+
2317+
arq = "FileSystem.txt"
2318+
2319+
if not(filExist(arq)):
2320+
creatFile(arq)
2321+
2322+
# readFile(arq)
2323+
system.menu()

0 commit comments

Comments
 (0)