Python Forum
atm machine problems - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: atm machine problems (/thread-12995.html)



atm machine problems - jy0013 - Sep-23-2018

I'm having some problems with the type of the account_balance. I'm not 100% sure what to do to change them to the right types. I also need to make sure that the withdrawal is divisible by 10, I know I use the % statement, but I don't know how the line of code would read. Any help is appreciated!

##display welcome message

print("Welcome to a Virtual Credit Union ATM!")


counter = 0
while counter < 3:
    pin = input("Please input your 4-digit PIN: ")

    if pin == 9876:
        print("Correct PIN, will continue to menu")
        break

    print("Incorrect PIN, please try again")
    counter += 1

if counter == 3:
    print("You're locked out, Goodbye")
else:
    print("Onto Menu options")


def menu():       ## Your menu design here
    print "1. View Account Balance"
    print "2. Withdraw cash"
    print "3. Make a deposit"
    print "4. Exit"


loop = True

while loop:          ## While loop which will keep going until loop = False
    menu()    ## Displays menu
    choice = input("Enter your choice [1-4]: ")

    if choice == 1:
        account_balance = (int, 'Your account balance is: $500')
        print(account_balance)

    elif choice == 2:
        print "Withdraw Cash, must be multiple of 10"
        withdraw = int(input('How much do you want to Withdraw?:'))

        if withdraw > account_balance:
            print("Insufficient funds")
            withdraw = int(input("Enter new amount to Withdraw: "))

        elif withdraw <= account_balance:
            balance = account_balance - withdraw
            print (' New Balance :', balance)

    elif choice == 3:
        print "Make Deposit"
        deposit = int(input('How much do you want to Deposit?:'))
        r = input("Are you sure you want to deposit ", deposit, "? [Y/N]")
        if choice == y:
            balance = account_balance + deposit
            print (' New Balance:', balance)

        elif choice == n:
            deposit2 = input("Enter the amount you want to deposit")
            balance = account_balance + deposit2
            print (' New Balance:', balance)

    elif choice == 4:
        print "Exit, Goodbye!"
        break

        loop = False # This will make the while loop to end as not the value of loop is set to False
    else:
        # Any integer inputs other than values 1-5 we print an error message
        raw_input("Wrong option selection. Enter any key to try again..")
error message:
File "/Users/jess/PycharmProjects/assignment2/assignment 1.py", line 54, in <module>
    r = input("Are you sure you want to deposit ", deposit, "? [Y/N]")
TypeError: [raw_]input expected at most 1 arguments, got 3



RE: atm machine problems - ThiefOfTime - Sep-23-2018

Hi :)
The error occures because this type of string concatenation can be used in print but not generally. change the line
r = input("Are you sure you want to deposit ", deposit, "? [Y/N]")
to
r = input("Are you sure you want to deposit {}? [Y/N]".format(deposit))
and the error is gone ;) You are calling the input function and giving it these 3 arguments but all it needs is just one string, so you need to put the strings together before using it for input.

The % operator is easy to use. Just as a small reminder:
10 % 10 == 0
20 % 10 == 0
11 % 10 == 1
12 % 10 == 2
...
so just check:
if withdraw % 10 == 0:
     # then everything is good
else:
     # ask the user to input the amount again
What do you want to do in this line?
account_balance = (int, 'Your account balance is: $500')