Python program to get student details as input and print the result after updating the marks

Here, we are going to learn how to Python program to get student details as input and print the result after updating the marks in Python?
Submitted by Shivang Yadav, on February 14, 2021

Problem Statement: Python program to get student details as input and then print the result after updating the marks.

Problem Description: We need to get input from users for the roll number, name and marks of three subjects. Then we need to calculate the percentage and print result, and reprint it after giving extra marks.

Steps to get and put details of student:

  • Step 1: Create a class named Student.
  • Step 2: The method of the class, getStudentDetails() gets input from the user. printResult() calculates result and prints it.
  • Step 3: We will also add extra marks (9), to a subject.
  • Step 4: Then print the result.

Program to illustrate printing student result

class Student:
    def getStudentDetails(self):
        self.rollno=input("Enter Roll Number : ")
        self.name = input("Enter Name : ")
        self.physics =int(input("Enter Physics Marks : "))
        self.chemistry = int(input("Enter Chemistry Marks : "))
        self.maths = int(input("Enter Math Marks : "))

    def printResult(self):
        self.percentage = (int)( (self.physics + self.chemistry + self.maths) / 300 * 100 ); 
        print(self.rollno,self.name, self.percentage)

S1=Student()
S1.getStudentDetails()

print("Result : ")
S1.printResult()

S1.physics += 9

print("result after adding grace marks...")
S1.printResult()

Output:

Enter Roll Number : 001
Enter Name : John
Enter Physics Marks : 87
Enter Chemistry Marks : 45
Enter Math Marks : 95
Result : 
001 John 75
result after adding grace marks...
001 John 78

Python class & object programs »





Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.