Programming Homework Help

University of California Floating Point Value Python Programming Solved Practice

 

2.1.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.

2.1.3: Write a Python program that asks the user to enter an integer (n) and computes the value of
n+n*n+n*n*n+n*n*n*n = ?. The program must then print the formula, replacing the ‘n’
variables with the user input, and the ? with the calculation results. Numbers greater than
1,000 must have a comma separator. Print using a formatted string or the format function.
Example Output:
Please enter an integer: 5
5 + 5 * 5 + 5 * 5 * 5 + 5 * 5 * 5 * 5 = 780

2.1.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

2.1.5: Body Mass Index (BMI) is a number calculated from a person’s weight and height.
The metric formula for BMI is: weight / height2
where weight is in kilograms and height is in meters.
Write a program that:
a. clearly prompts user for weight and height in one input
b. performs BMI calculation
c. prints BMI calculation with an appropriate description
Example Output:
Enter Weight in kilograms and Height in meters (separated by a space): 110.2 1.83
Body Mass Index (BMI) for Weight 110.2 and Height 1.83: 32.91

2.2.6: Using a ‘for loop’ , write a program that calculated and prints all the leap years from 1899 to
2021. Make sure that you understand the rules for determining a leap year and use the
modulo operator to manually calculate leap years. Do not use the calendar library.
Then perform this calculation a second time using a ‘while loop’.
For each looping method, print all the year results on one comma separated line.

2.2.7: Rewrite this following ‘for loop’ as a ‘while loop’ and create a working program:
(Note that X is upper case because it is defined as a constant)

X = 10

for i in range(1, X + 1):

if X % i == 0:

print(i)