본문 바로가기

만든 기록들

온도 단위 바꾸기

# 화씨 온도에서 섭씨 온도로 바꿔주는 함수
def fahrenheit_to_celsius(fahrenheit):
    return(fahrenheit - 32) * 5 / 9

# 입력받기
temperature_lilst = input("섭씨 온도로 바꿀 화씨 온도를 입력해주세요. (여러개 입력시 한칸 띄어쓰기) : ").split()

# 화씨 온도에서 섭씨 온도로 바꿔주기
i = 0
while i < len(temperature_lilst):
    temperature_lilst[i] = round(fahrenheit_to_celsius(int(temperature_lilst[i])),2)
    i += 1

print(temperature_lilst)

결과

# 화씨 온도에서 섭씨 온도로 바꿔주는 함수
def fahrenheit_to_celsius(fahrenheit):
    return(fahrenheit - 32) * 5 / 9

# 입력받기
temperature_lilst = 
input("섭씨 온도로 바꿀 화씨 온도를 입력해주세요. (여러개 입력시 한칸 띄어쓰기) : ").split()
#.split()로 여러개 입력했을 때 띄어쓰기로 나눈다.

# 화씨 온도에서 섭씨 온도로 바꿔주기
i = 0
while i < len(temperature_lilst):
    temperature_lilst[i] = round(fahrenheit_to_celsius(int(temperature_lilst[i])),2)
    i += 1

print(temperature_lilst)

'만든 기록들' 카테고리의 다른 글

단어 퀴즈  (0) 2020.03.12
숫자 야구  (0) 2020.02.12
환전 서비스  (0) 2020.02.12
숫자 맞추기 게임  (0) 2020.02.12
거스름돈 계산기  (0) 2020.02.12
댓글