Write a program that displays a table of ten distance equivalents in miles and kilometers. See Example output. You must generate the table by running a function inside a loop in main. Generate a random integer from 10 to 60, inclusive, in each loop cycle. Use this latter value as the miles argument to the function. Repeat: The function prints the table.  Print  the miles in a column 5 characters wide with 2 decimals and the kilometers in a column 13 characters wide with 5 decimals. Use the column formatting concepts at the end of Chapter 2, not tabs or other methods not in this course. Please include your psudocode to explain your code.  Example output MILES   KILOMETERS 52.00     83.68568 11.00     17.70274 40.00     64.37360 21.00     33.79614 14.00     22.53076 23.00     37.01482 48.00     77.24832 22.00     35.40548 15.00     24.14010 16.00     25.74944

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

program5_1.py Part 1
Write a program that displays a table of ten distance equivalents in miles and kilometers. See Example output. You must generate the table by running a function inside a loop in main. Generate a random integer from 10 to 60, inclusive, in each loop cycle. Use this latter value as the miles argument to the function. Repeat: The function prints the table.  Print  the miles in a column 5 characters wide with 2 decimals and the kilometers in a column 13 characters wide with 5 decimals. Use the column formatting concepts at the end of Chapter 2, not tabs or other methods not in this course. Please include your psudocode to explain your code. 

Example output

MILES   KILOMETERS
52.00     83.68568
11.00     17.70274
40.00     64.37360
21.00     33.79614
14.00     22.53076
23.00     37.01482
48.00     77.24832
22.00     35.40548
15.00     24.14010
16.00     25.74944

program5_2.py Part 2
Write another program that generates another table with the same columns and decimals but by using a function that returns the kilometers for a specified miles parameter. Use a loop in main and generate random integers as before, but catch the value returned by the function and use it in the loop to print a line of the table. Repeat: The table is printed in main. Please include your psudocode to explain your code. 

Expert Solution
Step 1

Hey, as per bartleby rules (given to the respective subject matter expert) we can not answer more than 1 answers at a time, try posting the answer again, mentioning that you want the part 2 of the question to be solved.

But here, Now i am writing the code for the above stated problem(part 1):

CODE IN PYTHON:

import random

def toKilometers(miles): 

          return miles * 1.60934         

print("MILES KILOMETERS")         

for i in range(10):

             miles = random.randrange(10, 61) * 1.0

             km = toKilometers(miles)

            print("{0:.2f} {1:.5f}".format(miles, km))

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY