Skip to content

Commit 3070e4c

Browse files
committed
feat: Add program for combining list and dictionary together
This commit adds a new program that combines a list and a dictionary together. The program prompts the user to enter the number of objects to add to the list, and then runs a loop to enter the objects in the list. The program also includes parameters for name, age, and gender, and allows for updating parameters such as profession, location, and education. It provides a menu with options to show and update by name, show and update by index, search for a student, delete a student, add a new student, restart the program, and close the program. In case of multiple users with the same name, the program displays a menu of all users with the same name and allows the user to select which user to update. The program also includes robust error handling and the ability to show all students in the list. This commit addresses the following user stories: - As a user, I want to be able to combine a list and a dictionary together. - As a user, I want to be able to add, remove, view, and update students in the list. - As a user, I want to be able to search for a student by name. - As a user, I want to be able to delete a student from the list. - As a user, I want to be able to add a new student to the list. - As a user, I want to be able to restart the program. - As a user, I want to be able to close the program. This commit also includes the following recent commits: - chore: Update dictionary values and remove unnecessary code - Refactor student functions and add global variables - Update execution count and remove unnecessary code in Python_Class.ipynb - Add code for removing 'Manav' from the list - Update execution count and odds list in Python_Class.ipynb - Add code for generating lists of even and odd numbers without using loops - Add code to remove all occurrences of number 9 from a list - ci: add .deepsource.toml - Add student management functionality - Revert "Add student management functionality"
1 parent 8b473ac commit 3070e4c

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

dictionary.ipynb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@
9191
"print(manav[\"school\"])\n",
9292
"print(manav[\"location\"])"
9393
]
94+
},
95+
{
96+
"cell_type": "markdown",
97+
"metadata": {},
98+
"source": [
99+
"write a program to combine list and dictionary together.\n",
100+
"ask user how many objects to enter in the list\n",
101+
"run a loop to enter the objects in the list\n",
102+
"parameters: name, age, gender, \n",
103+
"update parameters: profession, location, education\n",
104+
"show menu - show and update by name -> search by name in lowercase\n",
105+
" - show and update index\n",
106+
" - search for student\n",
107+
" - delete student\n",
108+
" - add new student\n",
109+
" - restart program\n",
110+
" - close program\n",
111+
"in case of multiple user with same name:\n",
112+
" - show menu of all users with same name\n",
113+
" - user can select which user is which -> number selection\n",
114+
" - \"Which user would you like to update?\"\n",
115+
"robust error handling\n",
116+
"show all students in list"
117+
]
94118
}
95119
],
96120
"metadata": {

student_database.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import os
2+
students = []
3+
4+
def add_student():
5+
num_students = int(input("Enter the number of students: "))
6+
7+
for i in range(num_students):
8+
student = {}
9+
student["name"] = input("Enter the name of the student: ")
10+
student["age"] = input("Enter the age of the student: ")
11+
student["gender"] = input("Enter the gender of the student: ")
12+
students.append(student)
13+
14+
def remove_student():
15+
name = input("Enter the name of the student to remove: ")
16+
for student in students:
17+
if student["name"] == name:
18+
students.remove(student)
19+
print("Student removed successfully")
20+
break
21+
else:
22+
print("Student not found")
23+
24+
def view_student():
25+
name = input("Enter the name of the student to view: ")
26+
for student in students:
27+
if student["name"] == name:
28+
print(f"Name: {student['name']}")
29+
print(f"Age: {student['age']}")
30+
print(f"Gender: {student['gender']}")
31+
break
32+
else:
33+
print("Student not found")
34+
35+
def display_all_students():
36+
for student in students:
37+
print(f"Name: {student['name']}")
38+
print(f"Age: {student['age']}")
39+
print(f"Gender: {student['gender']}")
40+
41+
def update_student():
42+
name = input("Enter the name of the student to update: ")
43+
for student in students:
44+
if student["name"] == name:
45+
student["name"] = input("Enter the name of the student: ")
46+
student["age"] = input("Enter the age of the student: ")
47+
student["gender"] = input("Enter gender of student")
48+
49+
50+
51+
52+
def start():
53+
print("Welcome to Student Database")
54+
print("1. Add Student")
55+
print("2. Remove Student")
56+
print("3. View Student")
57+
print("4. Display all students")
58+
print("5. Update Student")
59+
print("6. Restart Program")
60+
print("7. Exit Program")
61+
62+
choice = int(input("Enter your choice: "))
63+
64+
if choice == 1:
65+
add_student()
66+
elif choice == 2:
67+
remove_student()
68+
elif choice == 3:
69+
view_student()
70+
elif choice == 4:
71+
display_all_students()
72+
elif choice == 5:
73+
update_student()
74+
elif choice == 6:
75+
os.system("python3 student_database.py")
76+
elif choice == 7:
77+
os.exit()

0 commit comments

Comments
 (0)