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:4 | ISBN:978013274719 | Edition: 6

Question

(Conversion from miles to kilometers) Write a program that displays the following
table (note that 1 mile is 1.609 kilometers):
Miles          Kilometers
1                    1.609
2                    3.218
...
9                  15.481
10                16.090

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

#5.4.Table
miles_to_km = 1.609
#display a header for the table
print("Miles   Kilometers")
#loop the condition
for i in range(1, 11):
    km = i * miles_to_km
    print(i,"           ",round(km, 3))


 

0 0

Discussions

Post the discussion to improve the above solution.