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:
Y Daniel Lang
Chapter:
.loops
Exercise:
Programming Excercises
Question:3 | ISBN:978013274719 | Edition: 6

Question

(Conversion from kilograms to pounds) Write a program that displays the following table (note that 1 kilogram is 2.2 pounds):
Kilograms     Pounds
   1                    2.2
   3                   6.6
...
197                433.4
199                437.8

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Program:

POUNDS_PER_KILOGRAM = 2.2
#disply the header for table
print("Kilograms"," ", "Pounds")
#loop to iterate upto 200 with step 2
for i in range(1,200,2):
    #Convert the kilograms to pounds
    pounds=i * POUNDS_PER_KILOGRAM
    #Display the output
    print(i,"           ",round(pounds,2))    


Output:

Python 3.2.1 (default, Jul 10 2011, 21:51:15) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
Kilograms   Pounds
1             2.2
3             6.6
5             11.0
7             15.4
9             19.8
11             24.2
13             28.6
15             33.0
17             37.4
19             41.8
21             46.2
23             50.6
25             55.0
27             59.4
29             63.8
31             68.2
33             72.6
35             77.0
37             81.4
39             85.8
41             90.2
43             94.6
45             99.0
47             103.4
49             107.8
51             112.2
53             116.6
55             121.0
57             125.4
59             129.8
61             134.2
63             138.6
65             143.0
67             147.4
69             151.8
71             156.2
73             160.6
75             165.0
77             169.4
79             173.8
81             178.2
83             182.6
85             187.0
87             191.4
89             195.8
91             200.2
93             204.6
95             209.0
97             213.4
99             217.8
101             222.2
103             226.6
105             231.0
107             235.4
109             239.8
111             244.2
113             248.6
115             253.0
117             257.4
119             261.8
121             266.2
123             270.6
125             275.0
127             279.4
129             283.8
131             288.2
133             292.6
135             297.0
137             301.4
139             305.8
141             310.2
143             314.6
145             319.0
147             323.4
149             327.8
151             332.2
153             336.6
155             341.0
157             345.4
159             349.8
161             354.2
163             358.6
165             363.0
167             367.4
169             371.8
171             376.2
173             380.6
175             385.0
177             389.4
179             393.8
181             398.2
183             402.6
185             407.0
187             411.4
189             415.8
191             420.2
193             424.6
195             429.0
197             433.4
199             437.8
>>> 

 

0 0

Discussions

Post the discussion to improve the above solution.