jeudi 15 décembre 2016

Python ATM Keep a Total of Balances

I'm stuck on my ATM program. I was wondering how you could use a function in an if statement to keep a total of different types of balances in a ATM Withdraw function. Here is my program so far:

accNumber = 5678
accPin= 2378

## Deposit ##

dep_sav1 = 0
dep_sav2 = 0
dep_checking = 0
dep_amtInput = 0 
total_deposits = 0

## Withdraw ##

with_sav1 = 0
with_sav2 = 0
with_checking = 0
withdrawAccIn = 0
totalwithsav1 = 0
totalwithsav2 = 0
totawithchk = 0
totalwithAll = 0
endSav1 = 1500
endSav2 = 5000
endWithChk = 500

## Account Options ##

sav1 = 1500
sav2 = 5000
checking1 = 500

## balance ##

acc_bal = 0
endBal = 0

## main ##

def main():
    welcome()
    validLogin()
    transactTypeIn()
def welcome():
    print("Welcome to Python ATM!")

## Valig Log In ##
def validLogin():
    global accNumber
    NotLoggedIn = True
    while NotLoggedIn == True:
        try:
            userInput = int(input("Enter your account number: "))
            if userInput == accNumber:
                print("Valid Account Number: ")
                validPin()
                NotLoggedIn = False
            else:
                print("Incorrect Account Number: ")
        except:
            print("Cannot Recognize Account Numer: ")

def validPin():
    global accPin
    NotValidPin = True
    while NotValidPin == True:
        try:
            pinInput = int(input("Enter your pin number: "))
            if pinInput == accPin:
                print("Valid Pin Number: ")
                NotValidPin = False
            else:
                print("Incorrect Pin Number: ")
        except:
            print("Cannot Recognize Pin Number: ")
## Transaction Types ##

def transactTypeIn():
    try:
        transactTypeIn = int(input("Please select the transaction you would like to do: 1 - Deposit, 2 - Withdraw, 3 - Balance Inquiry, 4 - Recipt:  "))
        if transactTypeIn == 1:
            deposit()
        elif transactTypeIn == 2:
            withdraw()
        elif transactTypeIn == 3:
            balance()
        elif transactTypeIn == 4:
            recipt()
        else:
            print("Sorry, that is an invalid transaction.")
    except ValueError:
        print("Sorry, that is not a valid input. Try again.")
    transactTypeIn()

## Withdraw ##

def withdraw():
    global totalwithAll


    withdrawAccIn = int(input("Please select the account you want to withdraw from: Press 1 for Savings, 2 for Second Savings Account, 3 for Checking Account, 4 for Exit "))
    withdrawAmt = int(input("Please enter the amount you want to withdraw: Please withdraw in multiple of 20: 20, 40, 60, 80, 100: "))
    if withdrawAmt in [20 , 40 , 60 , 80 , 100] and withdrawAmt + totalWithAll <= 750:
        if withdrawAccIn == 1:        
            if with_sav1 <= sav1:

                # process the withdraw
                print("You have withdrawn" , withdrawAmt, "from your first savings account.")
                # update balances
                ## sav1 ##
                ## totalwithAll ##
                ## withdraw savings account ##
            else:
                print('did not process')

        elif withdrawAccIn == 2:
            global with_sav2
            with_sav2 = int(input("Please enter the amount you want to withdraw: Please withdraw in multiple of 20: 20, 40, 60, 80, 100: "))
            if with_sav2 <= sav2:
                if with_sav2 == 20 or 40 or 60 or 80 or 100:
                    print(("You selected to withdraw") , with_sav2 , "from your second savings account. ")
        elif withdrawAccIn == 3:
            global with_sav2
            with_sav2 = int(input("Please enter the amount you want to withdraw: "))
            if with_sav2 in range (0, 1001):
                print("Transaction Successful: You have withdrew" , with_sav2 , "from your checking account.")

    else:
        print("Please withdraw in multiple of $20: ")



    transactTypeIn()

## Deposit #

def deposit():
    depAccIn = int(input("Please select the account you want to deposit to: Press 1 for Savings 1, 2 for Second Savings Account, 3 for Checking Account, 4 for Exit "))
    if depAccIn == 1:
        global dep_sav1
        dep_sav1 = int(input("Please enter the amount you want to deposit: "))
        if dep_sav1 in range (0, 1001):
            print("Transaction Sucessful: You have deposited" , dep_sav1 , "into your first savings account.")

    elif depAccIn == 2:
            global dep_sav2
            dep_sav2= int(input("Please enter the amount you want to deposit: "))
            if dep_sav2 in range (0, 1001):
                print("Transaction Succesful: You have deposited" , dep_sav2 , "into your second savings account.")

    elif depAccIn == 3:
            global dep_checking
            dep_checking = int(input("Please enter the amount you want to deposit: "))
            if dep_checking in range (0, 1001):
                print("Transaction Successful: You have deposited", dep_checking , "into your checking account.")
    transactTypeIn()

## Balance ##

def balance():
    global acc_bal
    if acc_bal == 3:
        print("Your current balance is: $" , (sav1 + dep_sav1) , "In your first savings account.")
        print("Your current balance is: $" , (sav2 + dep_sav2) , "In your second savings account.")

main()

The issue is in this block: I'm not sure how to continue to update balances. Are there any ways to keep track of a total for when a user wants to use the program?

def withdraw():
        global totalwithAll


        withdrawAccIn = int(input("Please select the account you want to withdraw from: Press 1 for Savings, 2 for Second Savings Account, 3 for Checking Account, 4 for Exit "))
        withdrawAmt = int(input("Please enter the amount you want to withdraw: Please withdraw in multiple of 20: 20, 40, 60, 80, 100: "))
        if withdrawAmt in [20 , 40 , 60 , 80 , 100] and withdrawAmt + totalWithAll <= 750:
            if withdrawAccIn == 1:        
                if with_sav1 <= sav1:

                    # process the withdraw
                    print("You have withdrawn" , withdrawAmt, "from your first savings account.")
                    # update balances
                    ## sav1 ##
                    ## totalwithAll ##
                    ## withdraw savings account ##
                else:
                    print('did not process')

Aucun commentaire:

Enregistrer un commentaire