Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- pytorch
- Self-loop attention
- abstraction
- elif
- sigmoid
- Transformer
- neural net
- Attention
- XOR
- machine learning
- Set Transformer
- python practice
- sentence embedding
- GNN
- NLP
- word2vec
- Python
- Classificaion
- deep learning
- overfitting
Archives
- Today
- Total
Research Notes
[Python Practice] If Statement Example - Grade Calculator 본문
Programming Language/Python
[Python Practice] If Statement Example - Grade Calculator
jiachoi 2023. 7. 3. 16:28<Question 1>
# 절대 평가 방식으로 총 점수가 90점 이상이면 A를, 80점 이상 90점 미만이면 B를,
70점 이상 80점 미만이면 C를, 60점 이상 70점 미만이면 D를, 60점 미만이면 F를 부과하는 수업입니다.
# 성적이 A일 경우 "You get an A"를, B일 경우 "You get a B"를, C일 경우 "You get a C"를,
D일 경우 "You get a D"를, F일 경우 "You fail"을 출력하는 함수를 쓰세요.
<Answer 1>
def print_grade(midterm, final):
total = midterm + final
if total >= 90 :
print("You get an A")
elif total >= 80:
print("You get a B")
elif total >= 70:
print("You get a C")
elif total >= 60:
print("You get a D")
else:
print("You fail")
print_grade(40, 45)
print_grade(20, 35)
print_grade(30, 32)
print_grade(50, 45)
You get a B
You fail
You get a D
You get an A
<Explanation 1>
일단 중간고사와 기말고사의 총 점수를 계산해주는 함수를 정의한다.
=> def print_grade(midterm, final):
total = midterm + final
if문을 사용하여 총점수가 90점 이상일경우 실행부분을 정의한다.
=> if total >= 90:
print("You get an A")
그 외는 elif를 사용하여 학점마다 범위와 실행부분을 정의하여 해주면 된다 .

학점계산기 예시 결과 출력화면
'Programming Language > Python' 카테고리의 다른 글
[Python Practice] While/If Statement - Find compound interest costs (0) | 2023.07.03 |
---|---|
[Python Practice] While, If Statement - Find factors (0) | 2023.07.03 |
[Python Practice] While Statement Example - Print Divisible Numbers (0) | 2023.07.03 |
[Python] Control Statement: While, If/Else/Elif (0) | 2023.07.03 |
[Python Practice] Determine even/odd number (0) | 2023.07.03 |