I am stuck in my code - Either import error or indentation error

<<import BankAccount


def menu():
    print("1. Deposit")
    print("2. Withdrawal")
    print("3. Display balance")
    print("4. Display interest")
    print("5. Exit program")

def invalidNumber(x):
    try:
        if x % 1 > 0:
            print("Invalid input")
            return menu()
    except TypeError:
        print("invalid input")
        return menu()

def menuOptions():
    x = int(input("Choose an option: "))
    if x == 1:
        z = int(input("How much?"))
        mySavings.deposit(z)
    elif x == 2:
        z = int(input("How much?"))
        mySavings.withdraw(z)
    elif x == 3:
        print("Your balance is: ", mySavings.getBalance())
    elif x == 4:
        rate = mySavings.calculateInterest()
        print(rate)
    else:
        print("Exit program")
        jack == 33

if __name__ == "__main__":
    mySavings = BankAccount(1000, 100)
    mySavings.BankAccount = BankAccount(1000, 100)
    try:
        print (menu())
        jack = 69
        while jack == 69:
            x = int(input("Choose an option: "))
            if x == 1:
                z = int(input("How much?"))
                mySavings.deposit(z)
            elif x == 2:
                z = int(input("How much?"))
                mySavings.withdraw(z)
            elif x == 3:
                print("Your balance is: ", mySavings.getBalance())
            elif x == 4:
                rate = mySavings.calculateInterest()
                print(rate)
            else:
                print("Exit program")
                jack == 33
    except invalidNumber(x):
        while jack == 69:
            menuOptions() >>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

I’m not really sure if this is part of your problem, or a typo, or just start-end indicators for this post (my guess), but the first line & last line:

<<import BankAccount
...
...
except invalidNumber(x):
        while jack == 69:
            menuOptions() >>

will likely throw an error. << & >> are bitwise operators in Python (bit shift operators).

I haven’t spotted any indentation problems in this script, but that doesn’t mean there aren’t any in the BankAccount import. The traceback of the error you are getting should help point to the error location.

As a last note, I can’t say for sure because I don’t know what’s in the imported module, but an import done like this will import the entire BankAccount module. Therefore in your main script when you reference BankAccount it is referencing the module, not a specific class or function. To me it looks like you have a BankAccount.py module that houses a BankAccount class

To clarify, if the BankAccount.py module is laid out something like this:

class BankAccount:
    def __init__(x, y):
        ...
    def deposit(z):
        ...
    def withdraw(z):
        ...
    # ...the rest of the bank account functions in the BankAccount class

You would need to import and reference it in your main script something like this:

import BankAccount
mySavings = BankAccount.BankAccount(1000, 100)
#  The first BankAccount references the module, the second references the class

Or

import BankAccount as bc
mySavings = bc.BankAccount(1000, 100)

Or

from BankAccount import BankAccount
mySavings = BankAccount(1000, 100)
# Now there is no need to reference the module every time

Finally there is the

import BankAccount as *

method, but I’m not going to go into that as this option can easily lead to conflicting naming schemes and is generally not recommended.

Hope this helps, sorry if this wasn’t what you were looking for.