491,994 views
42 votes
42 votes
Set up a Python program

Write a table of conversions from Celsius to Fahrenheit. To perform this conversion multiply by 9/
and add 32. Your table should have an appropriate heading. Print only for Celsius temperatures
divisible evenly by 20. Let the user input the stopping value (the Celsius value where the table stops

User Royvandewater
by
2.7k points

1 Answer

17 votes
17 votes

Answer:

# Prompt the user to enter the stopping value (in Celsius)

stop = int(input("Enter the stopping value in Celsius: "))

# Print the table heading

print("Celsius\tFahrenheit")

print("-------\t----------")

# Iterate over the range of Celsius temperatures divisible by 20

for celsius in range(0, stop + 1, 20):

# Convert the temperature to Fahrenheit

fahrenheit = celsius * 9/5 + 32

# Print the temperature in both Celsius and Fahrenheit

print(f"{celsius}\t{fahrenheit:.1f}")

Step-by-step explanation:

This program prompts the user to enter the stopping value in Celsius, and then uses a range-based for loop to iterate over the range of Celsius temperatures that are divisible by 20. For each temperature, it converts the temperature to Fahrenheit using the provided formula, and then prints the temperature in both Celsius and Fahrenheit. The output is formatted to display one decimal place for the Fahrenheit temperatures.

Tell me if this helped :)

User Anno
by
2.6k points