105k views
5 votes
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))

1 Answer

5 votes

Answer:

The program is as follows:

prod = 1

isum = 0

for i in range(4):

num = float(input())

prod*=num

isum+=num

avg = isum/4

print('{:.0f}'.format(prod))

print('{:.3f}'.format(avg))

Step-by-step explanation:

This initializes the product to 1

prod = 1

..... and sum to 0

isum = 0

The following iteration is repeated 4 times

for i in range(4):

Get input for each number

num = float(input())

Calculate the product

prod*=num

Add up the numbers

isum+=num

This calculates the average

avg = isum/4

Print the products

print('{:.0f}'.format(prod))

Print the average

print('{:.3f}'.format(avg))

User Infiniti Fizz
by
6.1k points