题目描述
对三个整数a,b,c,求a÷b的值,结果保留c位有效数字,c>=0 且 c<=1000
输入
输入包括多行数据,每行是用空格分隔的三个整数a b c,其中c>=0 且 c<=1000。
输出
对输入的每行数据,输出包括一行,a÷b的保留c位有效数字的结果,如果b等于0,该行输出error
样例输入 Copy
1 2 1
1 2 0
0 2 2
样例输出 Copy
0.5
1
0.00
from decimal import Decimal
while True:
a,b,c=map(float,input().split())
if b!=0:
d=a/b
c=int(c)
a = Decimal(str(d))
a = round(a,c)
print(a)
elif b==0:
print('error')
如果不用补零
while True:
a,b,c=map(float,input().split())
if b!=0:
d=a/b
c=int(c)
if c!=0:
print((int(d*10.0**c+0.5))/10.0**c)
else:
print((int(d*10.0**c+0.5))//10**c)
elif b==0:
print('error')