作为一项作业,我正在 python 中制作一个简单的界面,它可以显示余额、添加该余额、从该余额中取出资金、检查利率,最后检查之前完成的三个操作。这将是 choice == 5。那么我应该在底部 def 中写什么才能做到这一点呢?
usd = 500
def main():
print("""
1. Balance
2. Add
3. Retrieve
4. Interest
5. Last Changes
""")
choice = int(input("Choose: "))
if choice == 1:
global usd
balance()
elif choice == 2:
add()
elif choice == 3:
retrieve()
elif choice == 4:
interest()
elif choice == 5:
changes()
def balance():
global usd
print("Balance: ", round((usd),2))
main()
def add():
global usd
amount = int(input("How much do you want to add? "))
usd = amount + usd
print("New balance = ", round((usd),2))
main()
def retrieve():
global usd
amount = int(input("How much do you want to retrieve: "))
usd = usd - amount
print("New balance = ", round((usd),2))
main()
def interest():
global usd
if usd<=1000000:
usd = ((usd/100)*101)
print("New balance: ", round(((usd/100)*101), 2))
elif usd>=1000000:
usd = ((usd/100)*102)
print("New balance: ", round(((usd/100)*102), 2))
main()
def changes():
main()
main()
所需的输出看起来有点像这样;
Choose: 5
+6105
-500000
+1110000
三国纷争
相关分类