125k views
2 votes
Write a program that displays a table of whole number Celsius temperatures in a range provided by the user and converts each to their Fahrenheit equivalents. The formula for converting a temperature from Celsius to Fahrenheit is: F space equals space 9 over 5 space C space plus space 32 The output for this assignment must use a loop to display the table. An example table looks like this (x and y = temperatures in the user-specified range) :

User OneGuyInDc
by
8.0k points

1 Answer

4 votes

Answer:

# Get the range of Celsius temperatures from the user

start_celsius = int(input("Enter the starting Celsius temperature: "))

end_celsius = int(input("Enter the ending Celsius temperature: "))

# Print the table header

print("Celsius | Fahrenheit")

print("-" * 24)

# Loop through the range and convert to Fahrenheit

for celsius in range(start_celsius, end_celsius + 1):

fahrenheit = (9 / 5) * celsius + 32

print(f"{celsius}°C | {fahrenheit}°F")

Step-by-step explanation:

In this program, the user is prompted to enter the starting and ending Celsius temperatures. The program then uses a for loop to iterate through the range of Celsius temperatures, converting each temperature to Fahrenheit using the provided formula, and displaying the table with both Celsius and Fahrenheit values.

User Tagyro
by
8.3k points