Saturday, November 20, 2021

Python - for loop with inflation as an example for 10 years

#for loop 11/20
#print numbers from 1 to 10
#i=0
#for i in range(1):
# print(i)

# Find inflation based for an amount assuming a percentage of 8%
noOfYears=10
print('Enter inflation percentage')
inflationPercentage=float(input())
print ('Inflation Percentage is :'+str(inflationPercentage))
print('Enter amount ')
amount=float(input())
totalAmount=float(amount)
i=0
for i in range(noOfYears):
totalAmount=totalAmount+(float(totalAmount)*(inflationPercentage/100))
xTimes=int(totalAmount / amount)
#print(xTimes)
#print(totalAmount)

if xTimes==2:
print('Amount is 2x')
elif xTimes==3:
print('Amount is 3x ')
elif xTimes== 4:
print('Amount is 4x')
else:
print('Amount hasn\'t doubled yet')

print(str(totalAmount)+' after '+str(i)+' year')
print('Total inflated amount after '+str(noOfYears)+' \n for amount : '+str(amount)+' is : '+str(totalAmount))

---

Output

Enter inflation percentage

Enter inflation percentage

8

Inflation Percentage is :8.0

Enter amount

20000

Amount is 2x

43178.49994545574 after 9 year

Total inflated amount after 10

for amount : 20000.0 is : 43178.49994545574

No comments:

Post a Comment

Please add value. Sharing is caring