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_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
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.
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))
Step by step
Solved in 2 steps with 2 images