Python 학점 산출 코드

Gayeong Jeong·2021년 10월 13일
0

Step1. 점수에 따라 학점 산출

score=int(input("점수 몇 점?"))

if score >= 90:
print(" A " , end=" ")
elif score >= 80:
print(" B " , end=" ")
elif score >= 70:
print(" B " , end=" ")
elif score >= 60:
print(" B " , end=" ")
else:
print("F")
print("학점입니다.")

Step2. 정수를 입력했는지? 그렇지 않으면 다시 입력 (while true, continue)

while True:

score=int(input("점수 몇 점?"))

if score<0 or score>100:
    continue

if score >= 90:
    print(" A " , end=" ")
elif score >= 80:
    print(" B " , end=" ")
elif score >= 70:
    print(" B " , end=" ")
elif score >= 60:
    print(" B " , end=" ")
else:
    print("F")
print("학점입니다.")

Step3. 문자를 입력하는 오류가 발생한다면 다시 입력 (try, except)

while True:
try:
score=int(input("점수 몇 점?"))

    if score<0 or score>100:
        continue

    if score >= 90:
        print(" A " , end=" ")
    elif score >= 80:
        print(" B " , end=" ")
    elif score >= 70:
        print(" B " , end=" ")
    elif score >= 60:
        print(" B " , end=" ")
    else:
        print("F")
    print("학점입니다.")
except ValueError:
    print("숫자 입력해 줘 ")
    continue

0개의 댓글