Define class Test

Define class Test: The below Python program accepts the name and the duration(in minutes) of two tests as the input. The program prints the names of the two tests and the total duration(in minutes) as shown in the Example Input/Output section. Please define the class Test so that the program runs successfully.

Example Input/Output 1:
Input:
English I
90
English II
90

Output:
English I + English II
180

Explanation:
The duration of the test English I is 90.
The duration of the test English II is 90.
The total duration is 180.
Hence the output is
English I + English II
180

Example Input/Output 2:
Input:
Maths
120
Science
90

Output:
Maths + Science
210

class Test:
    def __init__(self,name,duration):
        self.name = name
        self.duration = duration
    def getName(self):
        return self.name
    def getDuration(self):
        return self.duration
test1name = input().strip()
test1duration = int(input().strip())
test2name = input().strip()
test2duration = int(input().strip())
test1 = Test(test1name, test1duration)
test2 = Test(test2name, test2duration)
print(test1.getName() + " + " + test2.getName())
print(test1.getDuration()+test2.getDuration())
Previous Article

Python - C - 013

Next Article

String Decryption - Character Position

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *