137k views
2 votes
Part 1 Given 3 integers, output their average and their product, using integer arithmetic. Ex: If the input is 10 20 5, the output is: 11 1000 Note: Integer division discards the fraction. Hence the average of 10 20 5 is output as 11, not 11.666666666666666. Submit the above for grading. Your program will fail the test cases (which is expected), until you complete part 2 below but check that you are getting the correct average and product using integer division. Part 2 Also output the average and product, using floating-point arithmetic. Ex: If the input is 10 20 5, the output is: 11 1000 11.666666666666666 1000.0

User KaeruCT
by
4.8k points

1 Answer

6 votes

Answer:

a = int(input("Enter first number: "))

b = int(input("Enter second number: "))

c = int(input("Enter third number: "))

avg = (a + b + c) / 3

product = a * b * c

print(str(int(avg)) + " " + str(product))

print(str(avg) + " {:.1f}".format(product))

Step-by-step explanation:

*The code is in Python

Ask the user for three integers, a, b, and c

Calculate their average, sum the numbers and divide by 3

Calculate their product

Print avg and product as integer numbers, be aware that I type casted the avg to int

Print avg and product as floating point numbers, be aware that I used format method to print one decimal for product

User Tom Lilletveit
by
5.1k points