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