-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchanupython.py
More file actions
53 lines (47 loc) · 1.65 KB
/
chanupython.py
File metadata and controls
53 lines (47 loc) · 1.65 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
:
python
# Define an empty dictionary to store student data (roll number as the key)
student_data = {}
# Function to add a new student
def add_student(roll_number, name, marks):
student_data[roll_number] = {'Name': name, 'Marks': marks}
# Function to display a student's data by roll number
def display_student(roll_number):
student = student_data.get(roll_number)
if student:
print(f"Roll Number: {roll_number}")
print(f"Name: {student['Name']}")
print(f"Marks: {student['Marks']}")
else:
print("Student not found.")
# Function to list all students
def list_students():
if student_data:
for roll_number, student in student_data.items():
print(f"Roll Number: {roll_number}")
print(f"Name: {student['Name']}")
print(f"Marks: {student['Marks']}")
else:
print("No students in the database.")
# Main program loop
while True:
print("Options:")
print("1. Add a new student")
print("2. Display a student's data")
print("3. List all students")
print("4. Quit")
choice = input("Enter your choice: ")
if choice == '1':
roll_number = input("Enter student's roll number: ")
name = input("Enter student's name: ")
marks = float(input("Enter student's marks: "))
add_student(roll_number, name, marks)
elif choice == '2':
roll_number = input("Enter student's roll number to display: ")
display_student(roll_number)
elif choice == '3':
list_students()
elif choice == '4':
break
else:
print("Invalid choice. Please try again."