Starting from:

$25

CS1114- Homework 2 Solved

Question 1:  

Textbook P79, Q34:

Body mass index (BMI) is a number calculated from a person’s weight and height. According to the Centers for Disease Control and Prevention, the BMI is a fairly reliable indicator of body fatness for most people. BMI does not measure body fat directly, but research has shown that BMI correlates to direct measures of body fat, such as underwater weighing and dual-energy X-ray absorptiometry. The formula for BMI is

𝑤𝑒𝑖𝑔ℎ𝑡/ℎ𝑒𝑖𝑔ℎ𝑡2 Where 𝑤𝑒𝑖𝑔ℎ𝑡 is in kilograms and ℎ𝑒𝑖𝑔ℎ𝑡 is in meters.

 

(a)  Write a program that prompts for metric weight and height and outputs the BMI.

For example, an execution could look like this:

Please enter weight in kilograms: 50

Please enter height in meters: 1.58

BMI is: 20.0288415

 

(b) Write a program that prompts for weight in pounds and height in inches, converts the values to metric, and then calculates the BMI.

Note: 1 pound is 0.453592 kilograms and 1 inch is 0.0254 meters.

For example, an execution could look like this:

Please enter weight in pounds: 135

Please enter height in inches: 71

BMI is: 18.8996914

 

 

 

Question 2:

Write a program that reads a 3 (decimal) digit positive integer, and print the sum of its digits. For example, an execution could look like this: Please enter a three digit positive integer: 123 The sum of its digits is 6.

 

 

Question 3:

Draw a tilted square with three 20 degree turns using Turtle Graphics. Expected output:

 

 

Question 4:

Suppose John and Bill worked for some time and we want to calculate the total time both of them worked. Write a program that reads number of days, hours, minutes each of them worked, and prints the total time both of them worked together as days, hours, minutes.

Note: there are 24 hours in a day and 60 minutes in an hour.

For example, an execution could look like this:

Please enter the number of days John has worked: 2

Please enter the number of hours John has worked: 12

Please enter the number of minutes John has worked: 15

Please enter the number of days Bill has worked: 3

Please enter the number of hours Bill has worked: 15

Please enter the number of minutes Bill has worked: 20

The total time both of them worked together is: 6 days, 3 hours and 35 minutes.

 

 

Question 5:

Textbook Page 78, Q32.

Python comes with hundreds of modules. Here is a challenge for you: find a module that you can import that will generate today’s date so you can print it. Use your favorite search engine for help in finding which module you need and how to use it. In the end, your task is to do the following:

print(‘The date today is:’, x)

The date today is: 2015-09-18

More products