Q:

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

belongs to collection: Python class & object programs

0

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 numbername 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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python class & object programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Arrays of Objects Example in Python... >>
<< Python program to add accounts in a bank (Bank Man...