Syntax issues for a simple ATM program

<Below this line, add a link to the EXACT exercise that you are stuck at.>

if CHOICE == 1

<In what way does your code behave incorrectly? Include ALL error messages.>

syntax error after first iteration.

<What do you expect to happen instead?>

Not sure why it isn’t running since it seems to have proper syntax.

```python

input(“Enter your Account Number”)
print (“Current Account Balance: 25000”)

strCHOICE = input (“Press 1 to make a Deposit or 2 to make a Withdrawal.”)

if CHOICE == 1
strDEPOSIT = input(“Press 1 to deposit to checking, 2 for savings”)
if DEPOSIT = 1
print(“Please insert check or money now”)
elif DEPOSIT = 2
print(“Please insert check or money now”)

elif CHOICE == 2
strWITHDRAWAL = input(“press 1 to draw funds from checking, press 2 for savings.”)
if WITHDRAWAL = 1
input(“How much would you like to withdraw today?”)
print(“Please remove your cash from the slot below”)
elif WITHDRAWAL = 2
input(“How much would you like to withdraw today?”)
print(“Please remove your cash from the slot below”)

endofprogram = input(“Thank you for your business, press enter to conclude this transaction.”)

<do not remove the three backticks above>

Please include a link to the exercise. Thank you.

Missing colon :

if CHOICE == 1:

and elsewhere.

Hey, thank you for your help.

This was not a specific lesson in codeacademy. I’m trying to just do some simple exercises on my own from the lessons here.

The colons definitely helped. I’m still getting a syntax error on the next if iteration [if DEPOSIT = 1:]. The error is on the equal sign but since 1 is a true condition, not sure why the syntax error.

= Assign new value
== Compare values

Hey thanks, Gandalf. So in this instance I’m actually comparing values since there is the option between integers 1 and 2? Is that why I should use ==?

IF statement in general is a evaluation statement, this means that the result of the evalution should be True or False:

When you compare for instance
x = 1
IF x==2 a logical result in this case will be False,

in case of
x = 1
IF x=2 will cause an error since IF statement does not know how to evaluate assigment

I gotcha. Ok, that’s actually helpful. I knew that theoretically, but having it explained that way more clearly demonstrates the difference.

Well the program at least runs now. But once the program runs and I’m asked to select 1 or 2 for deposit, an error generates. Is this because I haven’t set an int value after [if DEPOSIT == 1:]? I feel like I’m missing something that will turn the input into a value.

The “Variable” name in the IF statement should be the same name as the “Variable” in the input result.

I tried working that out, but I don’t see how they are different. Are you referring to the first IF statement? CHOICE?

if CHOICE == 1:
strDEPOSIT = input(“Press 1 to deposit to checking, 2 for savings”)
if DEPOSIT == 1:
print(“Please insert check or money now”)
elif DEPOSIT == 2:
print(“Please insert check or money now”)

Gandalf,

Ok, I think I am getting you. Should something like this go after line 7? DEPOSIT = int(DEPOSIT)

I ran it but to to no avail.

According to the line errors I’m getting I need to define most of these variables and I’m just not sure how. It tells me CHOICE isn’t defined, but I thought it was defined by the input string on line 4. I tried adding CHOICE = 1 which got me further but I realized that means CHOICE can’t equal 2. So I tried “1 or 2” but that didn’t seem to help. Any suggestions are immensely helpful. Thanks.

Current program:

input("Enter your Account Number: ")
print(“Current Account Balance: 25000”)

strCHOICE = input(“Press 1 to make a deposit or 2 to make a withdrawal.”)

if CHOICE == 1:
strDEPOSIT = input("Press 1 to deposit to checking, 2 for savings: ")
if DEPOSIT == 1:
print(“Please insert cash or checks into checking.”)
elif DEPOSIT == 2:
print(“Please insert cash or checks into savings.”)

elif CHOICE == 2:
strWITHDRAWAL = input(“press 1 to draw funds from checking, press 2 for savings.”)
if WITHDRAWAL == 1:
input(“How much would you like to withdraw today?”)
print(“Please remove your cash from the slot below”)
elif WITHDRAWAL == 2:
input(“How much would you like to withdraw today?”)
print(“Please remove your cash from the slot below”)

endofprogram = input(“Thank you for your business, press enter to conclude this transaction.”)

Hey, I think I finally figured it out.

I was not defining CHOICE as an int input and left it as a regular input string. I then copied this to the rest of the variables and it worked.

Thank you again!

input("Enter your Account Number: ")
print(“Current Account Balance: 25000”)

CHOICE = int(input("Press 1 to make a deposit or 2 to make a withdrawal: "))

if CHOICE == 1:
DEPOSIT = int(input("Press 1 to deposit to checking, 2 for savings: "))
if DEPOSIT == 1:
print(“Please insert cash or checks into checking.”)
elif DEPOSIT == 2:
print(“Please insert cash or checks into savings.”)

elif CHOICE == 2:
WITHDRAWAL = int(input(“press 1 to draw funds from checking, press 2 for savings.”))
if WITHDRAWAL == 1:
input(“How much would you like to withdraw today?”)
print(“Please remove your cash from the slot below”)
elif WITHDRAWAL == 2:
input(“How much would you like to withdraw today?”)
print(“Please remove your cash from the slot below”)

endofprogram = input(“Thank you for your business, press enter to conclude this transaction.”)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.