SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Repetition Structures
Exercise:
Programming Exercises
Question:6 | ISBN:9780132576376 | Edition: 2

Question

Celsius to Fahrenheit Table
Write a program that displays a table of the Celsius temperatures 0 through 20 and their Fahrenheit equivalents. The formula for converting a temperature from Celsius to Fahrenheit is
F = \frac{9}{5}C + 32
where F is the Fahrenheit temperature and C is the Celsius temperature. Your program must use a loop to display the table.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Celsius to Fahrenheit Table program code:

#Print a table of the Celsius temperatures
#0 through 20 and their Fahrenheit 
#equivalents.
print("Celsius\tFahrenheit")
print("-------------------")
#converting a temperature from 
#Celsius to Fahrenheit
for celsius in range(0, 21):
    fahrenheit = (9 / 5) * celsius + 32
    #Display output
    print(f"{celsius}\t\t\t\t{fahrenheit}")

Executed Output:

Celsius	      Fahrenheit
-------------------------
0				32.0
1				33.8
2				35.6
3				37.4
4				39.2
5				41.0
6				42.8
7				44.6
8				46.4
9				48.2
10				50.0
11				51.8
12				53.6
13				55.4
14				57.2
15				59.0
16				60.8
17				62.6
18				64.4
19				66.2
20				68.0

 

0 0

Discussions

Post the discussion to improve the above solution.