-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp_convert.py
More file actions
39 lines (36 loc) · 1.2 KB
/
temp_convert.py
File metadata and controls
39 lines (36 loc) · 1.2 KB
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
30
31
32
33
34
35
36
37
38
39
# Mark Dymek
# 3/9/25
# Purpose: Code a temp converter from F to C and C to F
# Contants:
fFREEZINGC = 0.0
fFREEZINGF = 32.0
fBOILINGC = 100.0
fBOILINGF = 212.0
fCONVERTC = 9.0 / 5.0
fCONVERTF = 5.0 / 9.0
NUMBER_CONVERT = ".1F"
# welcome message
print("Hello, welcome to Mark's temperature converter!")
# inputs
fTemp = float(input("Please enter a temp: "))
sScale = input("Enter F or f for Fahrenheit or C or c for Celsius: ")
# did you enter a proper character?
if not (sScale == "F" or sScale == "f" or sScale == "C" or sScale == "c"):
print("You did not enter a F or C")
raise SystemExit
if sScale == "F" or sScale == "f":
if fTemp > fBOILINGF:
print("Temp cannot be greater than 212")
elif fTemp < fFREEZINGF:
print("Temp cannot be less than 32")
else:
fCel = (fTemp - fFREEZINGF) * fCONVERTF
print(f"The celsius equivalent is : {fCel:{NUMBER_CONVERT}}")
elif sScale == "C" or sScale == "c":
if fTemp < fFREEZINGC:
print("Temp cannot be less than 0")
elif fTemp > fBOILINGC:
print("Temp cannot be great than 100")
else:
fFahr = (fTemp * fCONVERTC) + fFREEZINGF
print(f"The Fahrenheit equivalent is : {fFahr:{NUMBER_CONVERT}}")