2017-04-02 2 views
-1

Dies ist das Programm, das ich geschrieben habe, aber ich kann kein Bankprogramm machen, das def Funktionen wie def withdrawl (current_amount, withdrawl_amount) verwendet. und verwendet if, elif und else für die Optionsliste. Bitte helfen Sie.Wie macht man ein Bankprogramm mit Def-Funktionen, kehrt zurück und wenn elif sonst?

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') 

Antwort

2

Sie sindelif und else bereits verwendet wird. Es sieht so aus, als würdest du mathematisch verstehen, wie man den Entzug auch verarbeitet.

Die Python 3-Dokumentation erläutert die Syntax zum Deklarieren und Aufrufen einer Funktion im Abschnitt 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) 
Verwandte Themen