Q:

ATM machine program using python programming language

belongs to collection: python projects for beginners

0

write python program for managing ATM Machine,

first of all the user needs passkey to enter program,

then a list appears:

  1. to withdraw money.
  2. press 2 to transfer money. 
  3. to deposit money.
  4. to display current balance.

 

do the program in  the following 3 different ways:

  • the first one without using any loops
  • the second is using an inifinite loop using while,
  • and the last way is using the modules concept( create a separated module called accounts.py and import it in the main python program.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

ATM machine program without using loops:

correct_passkey='4455'
balance=0
entered_passkey=input('welcome client, please enter passkey:')

if entered_passkey != correct_passkey:
    print('wrong passkey!')
else:
    choice=int(input('welcome,\npress 1 to withdraw money.\npress 2 to transfer money\npress 3 to deposit money\npress 4 to display current balance:'))
    if choice==1:
            if balance<=0:
             print('you do not have money!')
            else:
             amount=int(input('enter the amount money you want to withdraw:'))
             if amount>100000:
                print('you are not allowed to withdraw more than 100000')
             elif amount>=balance:
                 print("withdrawing is processing...")
                 balance=balance-amount
                 print("withdraw done!.")
    elif choice==2:
            money = int(input('enter money amount:'))
            if money <balance:
                print('not enough money in your balance to transfer.')
            else:
                c=int(input('enter account number you want to transfer to:'))
                count=-1
                print("transfering is processing...")
                balance=balance-money
                print("transfering done!.")
    elif choice==3:
            money=int(input('enter money amount:'))
            balance=balance + money
            print("deposit process done.")
    elif choice==4:
        print('Your balance is ', balance)
    else:
        print("invalid entry!")

 

with inifinite loops using while loop, and with lists(arrays):

accounts_numbers=[23410324,132432,9865665,596900,4654680,76432,86785342,5678888,734533,456045456]
accounts_passkeys=[2344,5433,7523,9806,4560,6454,5343,6565,3455,5677]
accounts_balances=[0,0,0,0,0,0,0,0,0,0]

while True:
 account_num=int(input('welcome, to atm, enter your account number:'))
 found_account=False
 counter=-1
 for a in accounts_numbers:
    counter=counter+1
    if a==account_num:
        found_account=True
        break

 if found_account == False:
    print('account number does not exists')
 else:
    passkey_counter=0 #this counter to count the number of login try times
    while True:
        passkey_counter=passkey_counter+1
        if passkey_counter>=4:
            print("this is the 4th try to signin, try again after 1 hour")
            break
        passkey=int(input('enter your passkey'))
        if passkey!=accounts_passkeys[counter]:
            print("wrong passkey, try again .")
        else:
           while True:   
            choice=int(input('1.withdraw money.\n2.transfer money to another account.\n3.deposit money.\n4.display balance.\n5.signout the atm'))
            if choice==1:
                money=int(input('enter money amount:'))
                if money>accounts_balances[counter]:
                    print('not enough money in your balance')
                else:
                    print("withdrawing is processing...")
                    accounts_balances[counter]=accounts_balances[counter]-money
                    print("withdraw done!. your new balance is ",accounts_balances[counter])
            elif choice==2:
                money = int(input('enter money amount:'))
                if money > accounts_balances[counter]:
                    print('not enough money in your balance')
                else:
                    c=int(input('enter account number you want to transfer to:'))
                    count=-1
                    for a in accounts_numbers:
                        count=count+1
                        if a==c:
                            accounts_balances[counter] = accounts_balances[counter] - money
                            accounts_balances[count]=accounts_balances[count]+money
                            print("transferring ",money," to account number/",c," is done successfuly.")
                            break
            elif choice==3:
                money=int(input('enter money amount to deposit:'))
                accounts_balances[counter] = accounts_balances[counter] + money
                print("doposit money is done. your new balance is ",accounts_balances[counter])
            elif choice==4:
                print('your balance =',accounts_balances[counter])
            elif choice==5:
                print("you will signout now. good bye")
                break
            else:
                print("invalid entry")
        break

 

 

ATM machine program using modules

we created a module named : accounts, and then imported it in the main program:

the accounts.py file:

################################################
#this is accounts.py
################################################
accounts_numbers=[23410324,132432,865665,595400,4654680,87657432,86785342,5678888,734533,456045456]
accounts_passkeys=[2344,5433,7523,9806,4560,6454,5343,6565,3455,5677]
accounts_balances=[0,0,0,0,0,0,0,0,0,0]

current_user_index=-1

def withdraw(money):
    if money > accounts_balances[current_user_index]:
        print('not enough money in your balance')
    else:
        accounts_balances[current_user_index] = accounts_balances[current_user_index] - money
        print('withdrawal done succefully')
def deposit(money):
    accounts_balances[current_user_index] =accounts_balances[current_user_index] + money
    print('deposit done succefully')

def transfer_money(money):
    if money > accounts_balances[current_user_index]:
        print('not enough money in your balance')
    else:
        c = int(input('enter account number you want to transfer to:'))
        count = -1
        for a in accounts_numbers:
            count = count + 1
            if a == c:
                accounts_balances[current_user_index] = accounts_balances[current_user_index] - money
                accounts_balances[count] = accounts_balances[count] + money
                print('money transfered succefully')
                break;

#############################################
##end of accounts.py file
############################################################

the main.py file:

#####################################
#this is main.py file
###################################
import accounts

account_num=int(input('welcome, to atm, enter your account number:'))
account_index=-1
counter=-1
for a in accounts.accounts_numbers:
    counter=counter+1
    if a==account_num:
        accounts.current_user_index=a
        break;

if accounts.current_user_index==-1:
    print('account number does not exists')
else:
    passkey=int(input('enter your passkey'))
    if passkey==accounts.accounts_passkeys[counter]:
     while True:
        choice=int(input('1.withdraw money.\n2.transfer money to another account.\n3.deposit money.\n4.display balance.\n5.exit'))
        if choice==1:
            accounts.withdraw(int(input('enter money amount:')))
        elif choice==2:
            money = int(input('enter money amount:'))
            if money > accounts.accounts_balances[counter]:
                print('not enough money in your balance')
            else:
                c=int(input('enter account number you want to transfer to:'))
                count=-1
                for a in accounts.accounts_numbers:
                    count=count+1
                    if a==c:
                        accounts.accounts_balances[counter] = accounts.accounts_balances[counter] - money
                        accounts.accounts_balances[count]=accounts.accounts_balances[count]+money
                        print('money transfered succefully')
                        break;
        elif choice==3:
            money=int(input('inter money amount:'))
            accounts.accounts_balances[counter] = accounts.accounts_balances[counter] + money
            print('deposit done succefully')
        elif choice==4:
            print('your balance equal',accounts.accounts_balances[counter])
        else:
            break

 

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
OOP and files handling python programming project... >>