subject

In Python: Given 4 floating-point numbers. Use a string formatting expression with conversion specifiers to output their product and their average as integers (rounded), then as floating-point numbers.
Output each rounded integer using the following:
print('{:.0f}'.format(your_value))< br /> Output each floating-point value with three digits after the decimal point, which can be achieved as follows:
print('{:.3f}'.format(your_value))< br /> My original code:
import math
num1 = float(input())
num2 = float(input())
num3 = float(input())
num4 = float(input())
num_product_float = num1 * num2 * num3 * num4
num_product = int(num_product_float)
num_average_float = (num1 + num2 + num3 + num4) / 4
num_average = int(num_average_float)
print('{:.0f} {:.0f}'.format(num_product, num_average))
print('{:.3f} {:.3f}'.format(num_product_float, num_average_float))
Input: 8.3 10.4 5.0 4.8
My output
2071 7 2071.680 7.125
Expected output
2072 7 2071.680 7.125
Here the expected outcome is rounding up for some reason so I edited my code:
num_product_float = num1 * num2 * num3 * num4
num_product = math. ceil(num_product_float)
So the first input set (8.3 10.4 5.0 4.8) is now coming out correct, but the second is wrong:
Input -2.3 -9.0 -6.5 -5.7
My output
767 -5 766.935 -5.875
Expected output
767 -6 766.935 -5.875
This seems to be rounding down, so I changed my code again:
num_average_float = (num1 + num2 + num3 + num4) / 4
num_average = math. floor(num_average_float)
Now I got the first and second input values correct, however the third is STILL coming out wrong:
Input: -15.2 10.3 7.8 -9.7
My output
11846 -2 11845.330 -1.700
Expected output
11845 -2 11845.330 -1.700
At this point I am lost, when I did the integer converson using int() I know that the program always drops the digits after the decimal however for some reason the output that is expected seems to be rounding up or down. So even though I adjusted using the math. ceil() and math. floor() code I still cant get the final input set to come out right.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 21:00
So im doing this school challenge and the teachers said whats the average text a student gets a day so i need to get about 20 in a day but dont know how can you guys 2163371293
Answers: 2
question
Computers and Technology, 23.06.2019 12:10
2. fabulously fit offers memberships for$35 per month plus a $50 enrollmentfee. the fitness studio offersmemberships for $40 per month plus a$35 enrollment fee. in how many monthswill the fitness clubs cost the same? what will the cost be?
Answers: 1
question
Computers and Technology, 23.06.2019 21:20
For positive constants a and b, the force between two atoms in a molecule is given f(r) = −a r2 + b r3 , where r > 0 is the distance between the atoms. note: a and b are upper case letters. (a) find f '(r) = (b) find the critical point for f(r). r = (c) find f ''(r) = (d) find the value of r so that f ''(r) = 0.
Answers: 1
question
Computers and Technology, 23.06.2019 22:30
Lakendra finished working on her monthly report. in looking it over, she saw that it had large blocks of white space. what steps could lakendra take to reduce the amount of white space?
Answers: 3
You know the right answer?
In Python: Given 4 floating-point numbers. Use a string formatting expression with conversion speci...
Questions
question
Mathematics, 17.03.2020 21:31