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)) Output each floating-point value with three digits after the decimal point, which can be achieved as follows: print('{:.3f}'.format(your_value))   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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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))

Output each floating-point value with three digits after the decimal point, which can be achieved as follows:
print('{:.3f}'.format(your_value))

 

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. 
 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Structure chart
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education