-
Notifications
You must be signed in to change notification settings - Fork 23
/
convert_f_to_c.py
29 lines (25 loc) · 1.12 KB
/
convert_f_to_c.py
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
################################################################################
#
# Program: Convert A Temperature From Fahrenheit To Celsius
#
# Description: Program to convert a temperature from Fahrenheit to Celsius
# using Python.
#
# YouTube Lesson: https://www.youtube.com/watch?v=i7UP4FU8twY
#
# Author: Kevin Browne @ https://portfoliocourses.com
#
################################################################################
# Prompt the user to enter the temperature in Fahrenheit using input(), the
# function will return the text entered by the user as a string, convert that
# string to a float value with float() and store it into fahrenheit (so that we
# can perform mathematical operations with the value).
fahrenheit = float(input("Temperature (F): "))
# Convert the temperature from fahrenheit to celsius using the formula:
# https://en.wikipedia.org/wiki/Celsius
celsius = (fahrenheit - 32) / 1.8
# Output the temperature in Celsius
print("Temperature (C):", celsius)
# Alternatively, we could use an f-string to output the temperature with
# 2 decimal digits of precision.
print(f"Temperature (C): {celsius:.2f}")