d = {}
temp = 10000
total = 0
def Expanse_calculator():
global temp
buy = True
while buy == True:
x = input("Enter the expenditure name:")
if x in d.keys():
price =float(input(f" Enter the '{x}' amount:"))
if temp>=price:
d[x]+=price
temp-=price
else:
print("insufficint found")
break
else:
price =float(input(f"Enter the '{x}'amount:"))
if temp>=price:
d[x]=price
temp-=price
else:
print("insufficint found")
break
total=sum(d.values())
while True:
ip = input("If you want to add any more expenditure [YES|NO]:").lower()
if ip == 'no':
buy = False
break
elif ip == 'yes':
Expanse_calculator()
else:
print("Invalid Entry")
Expanse_calculator()
print(total)
Above is my sample code While entering 'no' to my query in while loop its not terminating in first attempt
output i'm getting:
Enter the expenditure name:asd
Enter the 'asd'amount:123
If you want to add any more expenditure [YES|NO]:yes
Enter the expenditure name:asf
Enter the 'asf'amount:124
If you want to add any more expenditure [YES|NO]:no
If you want to add any more expenditure [YES|NO]:no
iam new to python plz help.