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)
上面是我的示例代码 在While循环中为我的查询输入“no”时,它不会在第一次尝试时终止
我得到的输出:
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
我不熟悉python plz帮助
相关问题 更多 >
编程相关推荐