Skip to content

Commit a25fd7e

Browse files
authored
Create unit4_ex4.2.3.py
1 parent 236c51a commit a25fd7e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

unit4_ex4.2.3.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# exercise 4.2.3 from unit 4
2+
'''
3+
Write a program that converts a temperature in degrees Celsius to a
4+
temperature in degrees Fahrenheit.
5+
The program receives a temperature from the user: either
6+
in degrees Celsius, with the suffix C, or in degrees Fahrenheit, with the suffix F.
7+
If the temperature is in degrees Celsius, convert it to degree
8+
s Fahrenheit, and if the temperature is in degrees Fahrenheit, convert it to degrees Celsius.
9+
10+
Guidelines
11+
The temperature can be either an integer or a non-integer (int or float).
12+
The suffix can be a lowercase letter or an uppercase letter (c, C, f, F).
13+
'''
14+
15+
temp = input("Enter a temperature: ")
16+
17+
# Check if temperature is in Celsius or Fahrenheit
18+
if temp[-1] == 'C':
19+
# Convert Celsius to Fahrenheit
20+
temp = float(temp[:-1]) * 9.0 / 5.0 + 32.0
21+
print(f"{temp}F")
22+
else:
23+
# Convert Fahrenheit to Celsius
24+
temp = (float(temp[:-1]) - 32.0) * 5.0 / 9.0
25+
print(f"{temp}C")

0 commit comments

Comments
 (0)