I have a variable called "P", and I want to limit the decimal numbers of a float. The input consists of three lines. The first two lines contain the integer values "a" and "b", respectively. The third line contains the integer p that defines the desired precision. 0<a,b,P≤100 is guaranteed. I want to display the message: "The result of a by b is X.", replacing X with the value of dividing a / b, given to P decimal places.
Ex:
input(a) = 10
input(b) = 5
input(p) = 3
expected result: "2.000"
Ex:
input(a) = 9
input(b) = 3
input(p) = 1
expected result: "3.0"
My code: a = 10, b = 5, p = 2
a = float(input())
b = float(input())
P = int(input())
y = round(a / b, P)
print(f'{a} / {b} = {y}.')
output = 10 / 5 = 2.0.
expected output = 10 / 5 = 2.00.