Write a python program to get student details as input and print the result after updating the marks


The Python program for a simple student management system. It allows you to input student details, update student marks, and print student details. Here's a breakdown of how the code works:

  • class Student: This defines a class named Student, which represents the student management system.
  • __init__(self): The constructor initializes an empty dictionary called student_details as an instance variable.
  • @property input_student_details(self): This is a property method that allows you to input student details. It prompts the user to enter the roll number, student name, and marks. The details are stored in the student_details dictionary under the roll number key.
  • update_student_marks(self): This method allows you to update a student's marks. It prompts the user to enter the roll number of the student to update and then the new marks. If the student is found in the student_details dictionary, their marks are updated.
  • print_student_details(self): This method allows you to print the details of a specific student. It prompts the user to enter the roll number of the student, and if the student is found, their roll number, name, and marks are printed.
  • The program creates an instance of the Student class called obj.
  • The code enters a while loop that displays a menu with four options: input student details, update student marks, print student details, and exit.
  • The user is prompted to enter their choice (1 to 4), and based on the choice, one of the methods of the obj instance is called.
  • If the user chooses option 4, the program exits the loop and ends.
  • If the user enters an invalid choice, an error message is displayed.

Source Code

class Student:
	def __init__(self):
		self.student_details = {}
 
	@property
	def input_student_details(self):	# input student details
		roll_number = input("Enter Roll Number : ")
		name = input("Enter Student Name : ")
		marks = float(input("Enter Marks : "))
		self.student_details[roll_number] = {'name': name, 'marks': marks}
		print("Marks Added successfully")
 
	def update_student_marks(self):	  # update student marks
		roll_number = input("Enter Roll Number of the Student to Update Marks : ")
		if roll_number in self.student_details:
			new_marks = float(input("Enter New Marks : "))
			self.student_details[roll_number]['marks'] = new_marks
			print("Marks updated successfully")
		else:
			print("Student not found")
 
	def print_student_details(self):	# print student details
		roll_number = input("Enter Roll Number of the student to view details : ")
		if roll_number in self.student_details:
			student = self.student_details[roll_number]
			print("Roll Number :", roll_number)
			print("Student Name :", student['name'])
			print("Marks :", student['marks'])
		else:
			print("Student not found")
 
obj = Student()
 
while True:
    print("\n ********* Student Management System *********  ")
    print("\n1. Input Student Details")
    print("2. Update Student Marks")
    print("3. Print Student Details")
    print("4. Exit")
 
    choice = input("\nEnter your Choice (1 to 4): ")
 
    if choice == '1':
        obj.input_student_details
    elif choice == '2':
        obj.update_student_marks()
    elif choice == '3':
        obj.print_student_details()
    elif choice == '4':
        print("Exiting the program")
        break
    else:
        print("Invalid Choice. Please Try Again !!!")
 
 

Output

 ********* Student Management System *********

1. Input Student Details
2. Update Student Marks
3. Print Student Details
4. Exit

Enter your Choice (1 to 4): 1
Enter Roll Number : ST001
Enter Student Name : Siva
Enter Marks : 430
Marks Added successfully

 ********* Student Management System *********

1. Input Student Details
2. Update Student Marks
3. Print Student Details
4. Exit

Enter your Choice (1 to 4): 2
Enter Roll Number of the Student to Update Marks : 467
Student not found

 ********* Student Management System *********

1. Input Student Details
2. Update Student Marks
3. Print Student Details
4. Exit

Enter your Choice (1 to 4): 3
Enter Roll Number of the student to view details : ST001
Roll Number : ST001
Student Name : Siva
Marks : 430.0

 ********* Student Management System *********

1. Input Student Details
2. Update Student Marks
3. Print Student Details
4. Exit

Enter your Choice (1 to 4): 4
Exiting the program

Example Programs