# Ask the user for a temperature
temp = input("Enter a temperature: ")
# Check if the input is a valid number
if temp.isdigit():
# Ask the user for the units
units = input("Enter the units (C or F): ")
# Convert the temperature to the other unit
if units.upper() == "C":
temp_f = float(temp) * 9/5 + 32
print(f"{temp}°C is equal to {temp_f:.1f}°F.")
elif units.upper() == "F":
temp_c = (float(temp) - 32) * 5/9
print(f"{temp}°F is equal to {temp_c:.1f}°C.")
else:
print("Invalid units. Please enter C or F.")
else:
print("Invalid temperature. Please enter a number.")
The output of the program would depend on what the user enters as input. Here are some example outputs:
Input: 32
F
Output: 32°F is equal to 0.0°C.
Input: 100
C
Output: 100°C is equal to 212.0°F.
Input: abc
C
Output: Invalid temperature. Please enter a number.
Input: 32
K
Output: Invalid units. Please enter C or F.
0 Comments