该程序计算折旧
我想继续询问用户输入,直到它给出有效的输入。
def CalculateDep(amount,nofYears,rate,yearOfPurchase):
for i in range(nofYears):
if (mop.lower() == "n" and i == 0):
percentile = rate * 0.005
elif(mop.lower() == "y" or mop.lower() == "n"):
percentile = rate * 0.01
dep = round((percentile)*amount, 2)
print("") # print blank line for readiblity
print("Dep Charge @" + str(percentile*100) + " % : " + str(dep))
print("On 31-03-" + str(yearOfPurchase+1))
amount = amount - (dep)
yearOfPurchase += 1
print("Value After Depreciation : " + str(round(amount, 2)))
amt = int(input("Enter the Amount : ")) #Initial value of asset
y = int(input("Enter the Number of years : "))
r = float(input("Enter The depreciation Rate : "))
yop = int(input("Enter The Year in Which The Asset is purchased : "))
mop = input("Purchased asset before 1st October ? Answer y or n : ")
CalculateDep(amt, y, r, yop)
通常这可以通过 while 循环来完成
while True:
try:
amt = int(input("Enter the Amount : "))
except ValueError:
print('please enter an int')
else:
break
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)