HR30 Day 12: Inheritance/Python

Jmnote (토론 | 기여)님의 2018년 8월 24일 (금) 20:04 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

개요[ | ]

class Person:
	def __init__(self, firstName, lastName, idNumber):
		self.firstName = firstName
		self.lastName = lastName
		self.idNumber = idNumber
	def printPerson(self):
		print("Name:", self.lastName + ",", self.firstName)
		print("ID:", self.idNumber)
import builtins
def print(*args,**kwargs):
    if "sep" not in kwargs and args[0] =="Grade: ":
        builtins.print(*args,**kwargs,sep="")
    else:
        builtins.print(*args,**kwargs)

class Student(Person):
    #   Class Constructor
    #   
    #   Parameters:
    #   firstName - A string denoting the Person's first name.
    #   lastName - A string denoting the Person's last name.
    #   id - An integer denoting the Person's ID number.
    #   scores - An array of integers denoting the Person's test scores.
    #
    # Write your constructor here
    def __init__(self, firstName, lastName, idNum, scores):
        super().__init__(firstName, lastName, idNum)
        self.scores = scores

    #   Function Name: calculate
    #   Return: A character denoting the grade.
    #
    # Write your function here
    def calculate(self):
        avg = sum(self.scores) / len(self.scores)
        if avg >= 90: return "O"
        if avg >= 80: return 'E'
        if avg >= 70: return 'A'
        if avg >= 55: return 'P'
        if avg >= 40: return 'D'
        return 'T'
line = input().split()
firstName = line[0]
lastName = line[1]
idNum = line[2]
numScores = int(input()) # not needed for Python
scores = list( map(int, input().split()) )
s = Student(firstName, lastName, idNum, scores)
s.printPerson()
print("Grade: ", s.calculate())
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}