-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdict.py
More file actions
116 lines (61 loc) · 1.94 KB
/
dict.py
File metadata and controls
116 lines (61 loc) · 1.94 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
import re
from datetime import datetime
print("******************Student Admission Form System*********************")
def valid_email():
while True:
try:
email = input("Enter email: ")
pattern = r'^[\w\.-]+@[\w\.-]+\.\w+$'
match = re.fullmatch(pattern, email)
if not match:
raise ValueError("Invalid Email Address")
return email
except ValueError :
print("Invalid Email Number")
def valid_phone():
while True:
try:
phone = input("Enter Phone (10 digits): ")
match = re.fullmatch(r'\d{10}', phone)
if not match:
raise ValueError("Invalid Phone")
return phone
except ValueError :
print("Invalid Phone Number")
def valid_DOB():
while True:
try:
dob = input("Enter DOB(dd-mm-yyyy): ")
datetime.strptime(dob,"%d-%m-%Y")
return dob
except ValueError:
print("Invalid Date of birth ")
def admission_time():
current_time = datetime.now().strftime("%d-%m-%Y %H:%M:%S")
print(current_time)
return current_time
name = input("Enter Name: ")
roll = input("Enter roll: ")
email = valid_email()
phone = valid_phone()
dob = valid_DOB()
time = admission_time()
student = {
"Name": name,
"Roll No": roll,
"Email": email,
"Phone": phone,
"Date": dob,
"Time": time
}
with open("students registration.txt","a") as stu :
stu.write({student[name]})
print("\nStudent Details:")
for key, value in student.items():
print(f"{key}: {value}\n")
def search_by_id():
print("Student details")
Roll = input("Enter No. to search : ")
if Roll in roll :
print(f" \n \n name : {name}\n roll : {roll}\n email:{email}\n phone : {phone}\n dob : {dob}\n time : {time} ")
search_by_id()