Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. (a) Write the design specifications for a program that calculates the volume of a box. Get the values for length, width, and height from

1. (a) Write the design specifications for a program that calculates the volume of a box. Get the values for length, width, and height from the user at the console. Print the resulting volume to the screen.

(b) Write the program.

(c) Copy the output from the program and paste it as a comment in the script of the program.

2. (a) Write the design specifications for a program that calculates the average of n integers. Get the number of integers, n, to be averaged from the user at the console. Using a loop, accumulate the sum of the n integers entered by the user. Calculate the average and print it to the screen. (Note: You can use any name for n.)

(b) Write the program.

(c) Copy the output from the program and paste it as comment in the script of the program.

For the following exercises (3 6) you do not need to write the design specifications.

3. Modify the temperature conversion program with a loop so that it executes 5 times. Add an introduction.

(Note: All the code in the text is in a folder called code)

# convert.py

# A program to convert Celsius temps to Fahrenheit

def main():

celsius =eval( input("What is the Celsius temperature? "))

fahrenheit = 9.0 / 5.0 * celsius + 32

print ("The temperature is", fahrenheit, "degrees Fahrenheit.")

main()

4. Modify the same program so that it computes and prints a table with of Celsius temperatures and the Fahrenheit equivalents every 10 degrees from 0C to 100C. (Note: This program does not require any input from the user.)

Celsius Fahrenheit

-----------------------

0 32

10 50

20 68

30 86

40 104

50 122

60 140

70 158

80 176

90 194

100 212

Make the numbers line up nicely using the format option:

print("{0:10} {1:10}".format(celsius,fahrenheit))

Inside {}, the first number indicates the position of the variable to be substituted in format (0 is the first and 1 is the second); after the :, the number indicates the width of the field (in this case, the field is 10 characters wide.

celsius = 5

fahrenheit = 41

print("{0:10} {1:10}".format(celsius,int(Fahrenheit)))

5 41

You can also use \t to move something one tab space to the right.

print("Cesius \t Fahrenheit")

Cesius Fahrenheit

5. Write a program that converts temperatures from Fahrenheit to Celsius.

6. Write a program that converts distances measured in kilometers to miles.

One kilometer is approximately 0.62 miles.

7. Write a program that converts meters to feet. [1 m = 1/0.3048]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

Students also viewed these Databases questions

Question

What are two techniques used to compress a project schedule?

Answered: 1 week ago

Question

What can Chandra do to correct her mistake?

Answered: 1 week ago