这是我编写的程序,但我无法创建使用def
等def withdrawl ( current_amount, withdrawl_amount )
函数的银行程序。并使用if
,elif
和else
作为选项列表。请帮忙。
balance = 2000
rt = 0.01
years = 0
while True:
print('===============================')
print(' Welcome to STEVENS UNIVERSAL BANK ')
print('Please Choose an Option')
print('Option 1: Withdrawl')
print('Option 2: Deposit')
print('Option 3: Check_Balance')
print('Option 4: Balance with Updated Interest')
print('Option 5: Exit')
print('===============================')
option = int(input('Choose an Option:'))
years = years + 1
if option == 1:
withdrawl = int(input('How much do you want to Withdrawl?:'))
balance = balance - withdrawl
print (' New Balance :', balance)
elif option == 2:
deposit = int(input('How much do you want to Deposit?:'))
balance = balance + deposit
print (' New Balance:', balance)
elif option == 3:
print('Balance:', balance)
elif option == 4:
balance = balance * ( 1 + ( 0.0001 * years ))
print (' Updated Balance', balance)
elif option == 5:
print (' Thank you for using THE STEVENS UNIVERSAL BANK ')
exit()
else:
print('Invalid Input')
答案 0 :(得分:2)
已使用elif
和else
。看起来你在数学上也理解如何处理退出。
Python 3文档解释了如何声明和调用函数的语法 在4.6. Defining Functions部分。
def fib(n): # write Fibonacci series up to n
"""Print a Fibonacci series up to n."""
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print()
# Now call the function we just defined:
fib(2000)