Starting from:

$25

METCSS521-Homework 2 Solved

1.     Write a Python program that prompts the user to enter a number. In one calculation, take that number, add 2, multiply by 3, subtract 6, and divide by 3.  Use an IF statement to check whether the input matches the calculated value and print the result of this check in a descriptive message.



2.     Prompt user for input and then print that input as a string, an integer, and a floating-point value. What data types can be input that will print without generating any errors?  
Answer this question at the end of your code by using a docscring comment.



3.     Write a Python program that asks the user to enter an integer (n) and computes the value of                      The program must then print the formula, replacing the ‘n’ variables with the  user input, and the ? with the calculation results.



4.     One way to determine whether an integer is even or odd is to divide the number by two and check the remainder. Write a three-line program that (1) prompts for a number, (2) converts the input to an integer and (3) prints the number 0 if the user input is even and the number 1 if the user input is odd.



5.     Body Mass Index (BMI) is a number calculated from a person’s weight and height. 
The formula for BMI is: weight / height2
   where weight is in kilograms and height is in meters.

Write a program that:

a.     prompts user for weight and height in one input

·  you decide whether to use Metric or convert from pounds & inches

·  remember to tell the user which measurement system you are expecting

·  to challenge yourself, try prompting the user for whether they want to enter Metric or Imperial

b.     performs BMI calculation

c.      prints BMI calculation

·  remember to tell the user that BMI is being printed


Chapter 2 Exercises

6.     Write a program that calculated and prints all the leap years from 1900 to 2020 (inclusive). Perform this calculation twice. First using a ‘for loop’ and then using a ‘while loop’.



7.     Rewrite this following ‘for loop’ as a ‘while loop’:
for i in range(1, X + 1):
 if X % i == 0:
             print(i)

More products