코드로 우주평화

Student's Final Grade 본문

나는 이렇게 학습한다/Algorithm & SQL

Student's Final Grade

daco2020 2022. 4. 11. 22:59
반응형

Description:

Create a function finalGrade, which calculates the final grade of a student depending on two parameters: a grade for the exam and a number of completed projects.

This function should take two arguments: exam - grade for exam (from 0 to 100); projects - number of completed projects (from 0 and above);

This function should return a number (final grade). There are four types of final grades:

  • 100, if a grade for the exam is more than 90 or if a number of completed projects more than 10.
  • 90, if a grade for the exam is more than 75 and if a number of completed projects is minimum 5.
  • 75, if a grade for the exam is more than 50 and if a number of completed projects is minimum 2.
  • 0, in other cases

Examples(Inputs-->Output):

100, 12 --> 100
99, 0 --> 100
10, 15 --> 100

85, 5 --> 90

55, 3 --> 75

55, 0 --> 0
20, 2 --> 0

*Use Comparison and Logical Operators.

 

Solution:

1. Divide the branch according to the presented conditions.
2. Return the final grade.

 

def final_grade(exam, projects):
    return (exam > 90 or projects > 10) * 100\
    or (exam > 75 and projects >= 5) * 90\
    or (exam > 50 and projects >= 2) * 75\
    or 0

I used 'or' to split a branch without an 'if'.

 

 

 

 

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

Century From Year  (0) 2022.04.13
Isograms  (0) 2022.04.12
Remove First and Last Character Part Two  (0) 2022.04.10
Total amount of points  (0) 2022.04.09
Transportation on vacation  (0) 2022.04.08