Python/Python__works

성적 grade 주기

말하는감자 2019. 5. 13. 15:39
total = 110

#---------------------------------------------------- 1번 방법
grade = {90: 'A', 80: 'B', 70: 'C', 60: 'D', 50: 'F',}
temp = total - 10 if total <= 100 else 90
grade_dict = {value: grade for value, grade in grade.items() if value >= temp}
grade_01 = min(grade_dict.items())
print(grade_01)

#---------------------------------------------------- 2번 방법
if total >= 90:
    grade_02 = 'A'
elif total >= 80:
    grade_02 = 'B'
elif total >= 70:
    grade_02 = 'C'
elif total >= 60:
    grade_02 = 'D'
else:
    grade_02 = 'F'
print(grade_02)

if else의 저주에서 벗어나는 방법 ㅡㅡ;

보통 1번 방법이 바로 생각이 안나기 때문에 2번 방법으로 짜놓고 고치는 편 ㅠㅠ..

'Python > Python__works' 카테고리의 다른 글

introducing python - strings  (0) 2019.05.31
python list comprehension  (0) 2019.05.23
dict comprehension  (0) 2019.05.13
지능형 리스트, list comprehension  (0) 2019.05.13
여백삭제, 유니코드출력  (0) 2019.05.13