'Python Simple Statistics
Needing a little help finishing this! I was able to get the final output of 1050.60 but struggling on the rest. Given 3 floating-point numbers. Use a string formatting expression with conversion specifiers to output their average and their product as integers, then as floating-point numbers.
Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print('%0.2f' % your_value)
Ex: If the input is:
10.3 20.4 5.0 the output is:
11 1050 11.90 1050.60
Here is what I have:
num1 = float(input())
num2 = float(input())
num3 = float(input())
average = (num1+num2+num3) /3
your_value = num1*num2*num3
print('%0.2f' % your_value)
Solution 1:[1]
num1 = float(input())
num2 = float(input())
num3 = float(input())
average = (num1+num2+num3) / 3
your_value = num1*num2*num3
print('%0.0f %0.0f %0.2f %0.2f' % (int(average), int(your_value), average, your_value))
# or:
print(f"{int(average)} {int(your_value)} {round(average,2)} {round(your_value,2)}")
if I understood your mean, correctly, it is your answer:
1. you must set display format for all values: %0.2f
2. use f-string in this format: f"{}" and add your value in {}
3. int: convert float to integer and round: round up number
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MoRe |
