0

I have been trying to code this ATM for an intro to coding class at uni, there are no syntax errors however the code stops running after the first line. Not sure where to go from here:

def cashpoint(truepin, balance):
    pin_attempt = input('Please enter your PIN: ')
    
    if input == truepin:
        return "Pin correct, please choose one of the following options"
        return '1: balance'
        return '2: cash and balance'
        return '3: mobile top up '
        option = input('option selected: ')
        
        if option == 1:
            return 'balance: ', balance
        elif option == 2:
            return 'balance: ', balance 
            withdrawal = input('please enter the amount you wish to withdraw: ')
        elif option == 3:
            input('please input the amount you wish to deposit into your account: ')
        else:
            return 'incorrect, please select one of the available options'
    else:
        return 'pin incorrect, please try again '
   

cashpoint(1234, 2350.25)

Any help would be appreciated. This is mostly for revision so please tell me where I've gone wrong and don't hold back!

Mark
  • 7,785
  • 2
  • 14
  • 34

2 Answers2

1

The problem is with the line if input == truepin:. It should be if pin_attempt == str(truepin):. This is because:

  1. you have assigned the name pin_attempt to the input() function call, not the name input (i.e. it's not input = input('Please enter your PIN: '), and
  2. (Assuming the true pin is a number), the input is going to be a string, so it needs to be converted to a string too

One other thing, because you were looking for feedback:

return is different to print. print() just shows some text in the command line, whereas return ends whatever function it is in and spits out whatever is next to the return. So when your code has return "Pin correct, please choose one of the following options", when it gets there, it ends the program, and spits out that. So you want to replace those return "some line"s on the lines where you don't want the function to end with print("some other line")s (replacing the strings with whatever you want)

Here is a good answer on return vs print, if you'd like to read more about it.

Hope this helps! Happy coding!

Mark
  • 7,785
  • 2
  • 14
  • 34
0

The return statement makes your function return the specified value to the caller and end its execution.

So once your programm reaches the first return statement inside your funktion, it returns the string "Pin correct, please choose one of the following options" to the caller of the function and proceeds execution at the point where your function was called.

Felix
  • 1,066
  • 1
  • 5
  • 22
  • While this is part of the solution, this wasn't the issue that was happening when the code was being run made clear by Katie saying `the code stops running after the first line` – Mark Jun 30 '23 at 12:03