Computer Science
Write a Python script to input temperature. Then ask them what units, Celsius or Fahrenheit, the temperature is in. Your program should convert the temperature to the other unit. The conversions are:
F = 9/5C + 32 and C = 5/9 (F 32).
Python
Python Control Flow
56 Likes
Answer
temp = float(input("Enter Temperature: "))
unit = input("Enter unit('C' for Celsius or 'F' for Fahrenheit): ")
if unit == 'C' or unit == 'c' :
newTemp = 9 / 5 * temp + 32
print("Temperature in Fahrenheit =", newTemp)
elif unit == 'F' or unit == 'f' :
newTemp = 5 / 9 * (temp - 32)
print("Temperature in Celsius =", newTemp)
else :
print("Unknown unit", unit)
Output
Enter Temperature: 38
Enter unit('C' for Celsius or 'F' for Fahrenheit): C
Temperature in Fahrenheit = 100.4
Answered By
29 Likes
Related Questions
Write a program using nested loops to produce a rectangle of *'s with 6 rows and 20 *'s per row.
Write a program to display all of the integers from 1 up to and including some integer entered by the user followed by a list of each number's prime factors. Numbers greater than 1 that only have a single prime factor will be marked as prime.
For example, if the user enters 10 then the output of the program should be:
Enter the maximum value to display: 10
1 = 1
2 = 2 (prime)
3 = 3 (prime)
4 = 2x2
5 = 5 (prime)
6 = 2x3
7 = 7 (prime)
8 = 2x2x2
9 = 3x3
10 = 2x5Given three numbers A, B and C, write a program to write their values in an ascending order. For example, if A = 12, B = 10, and C = 15, your program should print out:
Smallest number = 10
Next higher number = 12
Highest number = 15Ask the user to enter a temperature in Celsius. The program should print a message based on the temperature:
- If the temperature is less than -273.15, print that the temperature is invalid because it is below absolute zero.
- If it is exactly -273.15, print that the temperature is absolute 0.
- If the temperature is between -273.15 and 0, print that the temperature is below freezing.
- If it is 0, print that the temperature is at the freezing point.
- If it is between 0 and 100, print that the temperature is in the normal range.
- If it is 100, print that the temperature is at the boiling point.
- If it is above 100, print that the temperature is above the boiling point.