-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileHandlingProject.py
More file actions
62 lines (56 loc) · 1.94 KB
/
FileHandlingProject.py
File metadata and controls
62 lines (56 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
while True:
print("\n1..for add Student detail")
print("2..for read Student detail")
print("3..for delete Student detail")
print("4..for edit Student detail")
print("5..for exit")
choice = int(input("\nEnter Choice: "))
if choice == 1:
f = open("Student.csv","r+")
data = f.readlines()
name = input("Enter Name: ")
role = input("Enter Role: ")
f.write(f"\n{len(data)},{name},{role}")
f.close
if choice == 2:
f = open("Student.csv","r")
data = f.readlines()
print(data)
for i in data:
student_info = i.strip().split(',')
rollno , name, role = student_info
print(f"{rollno}\t{name}\t{role}")
f.close
if choice == 3:
f = open("Student.csv","r")
data = f.readlines()
f.close
for i in data:
student_info = i.strip().split(',')
rollno , name, role = student_info
print(f"{rollno}\t{name}\t{role}")
num = int(input("Enter number you want to delete: "))
data.pop(num)
f = open("Student.csv","w")
f.writelines(data)
f.close
if choice == 4:
f = open("Student.csv","r")
data = f.readlines()
f.close
for i in data:
student_info = i.strip().split(',')
rollno , name, role = student_info
print(f"{rollno}\t{name}\t{role}")
no = int(input("Enter your roll no:"))
student_info = data[no].strip().split(',')
rollno , name, role = student_info
newname = input(f"Enter your new name(old:{name})")
newrole = input(f"Enter your new role(old:{role})")
data[no] = f"{no},{newname},{newrole}\n"
print(data)
f = open("Student.csv","w")
f.writelines(data)
f.close
if choice == 5:
break