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 05:20
Write a program called assignment3 (saved in a file assignment3.java) that computes the greatest common divisor of two given integers. one of the oldest numerical algorithms was described by the greek mathematician, euclid, in 300 b.c. it is a simple but very e↵ective algorithm that computes the greatest common divisor of two given integers. for instance, given integers 24 and 18, the greatest common divisor is 6, because 6 is the largest integer that divides evenly into both 24 and 18. we will denote the greatest common divisor of x and y as gcd(x, y). the algorithm is based on the clever idea that the gcd(x, y) = gcd(x ! y, y) if x > = y and gcd(x, y) = gcd(x, y ! x) if x < y. the algorithm consists of a series of steps (loop iterations) where the “larger” integer is replaced by the di↵erence of the larger and smaller integer. this continues until the two values are equal. that is then the gcd.
Answers: 3
question
Computers and Technology, 22.06.2019 17:00
Acase study allows a more detailed look at the life of a single subject than any other study.
Answers: 3
question
Computers and Technology, 22.06.2019 22:30
Write a full class definition for a class named player , and containing the following members: a data member name of type string .a data member score of type int .a member function called setname that accepts a parameter and assigns it to name . the function returns no value.a member function called setscore that accepts a parameter and assigns it to score . the function returns no value.a member function called getname that accepts no parameters and returns the value of name .a member function called getscore that accepts no parameters and returns the value of score .this is what i have, aparently this is wrong: class player{private: string name; int score; public: void player: : setname (string n){name =n; }void player: : setscore (int s){score = s; }string player: : getname (){return name; }int player: : getscore (){return score; }};
Answers: 2
question
Computers and Technology, 23.06.2019 14:30
Select the correct answer. what does it indicate when a website displays https instead of http? a. the website is secure. b. there is no secure sockets layer. c. the secure sockets layer is hidden. d. the website is not secure.
Answers: 1
You know the right answer?
In Python: Given 4 floating-point numbers. Use a string formatting expression with conversion speci...
Questions
question
Mathematics, 12.11.2020 14:00
question
Computers and Technology, 12.11.2020 14:00
question
Business, 12.11.2020 14:00
question
Mathematics, 12.11.2020 14:00
Questions on the website: 13722361