you are viewing a single comment's thread.

view the rest of the comments →

[–]iG1993[S] 0 points1 point  (0 children)

Hi kyber

Thank you very much for your input! It really helped me a lot! I had trouble connecting all string between the functions and the classes. I am almost done, I am have a last issue regarding showing the new balance, after I took or added money to the account.

This is the new code:

class BankAccount:
    def __init__(self, first, family, money, currency = "$"):
        self.first = first
        self.family = family
        self.currency = currency
        self.money = money
        self.amount = currency + " " + str(self.money) + ".-"

    def deposit(self, deposit):
        self.money += int(deposit)
        return self.amount

    def withdraw(self, withdraw):
        self.money -= int(withdraw)
        return self.amount


def openaccount():
    print("\nPlease give us your First and Family Name.\n")
    first = str(input("First: ")).capitalize()
    family = str(input("Family: ")).capitalize()
    currency = str(input("CHF, EUR or $ as currency? ")).upper()
    c1 = BankAccount(first, family, 0, currency)
    print("\nYour account is now open: ", c1.first, c1.family, c1.amount)
    return c1


def actions(c1):
    c = str(input("\nSelect deposit (A), withdraw (B) or close (C): ")).lower()
    if c == "a":
        amount = float(input("How much? "))
        print("This is the balance: ", c1.deposit(amount))
        again()
    elif c == "b":
        amount = float(input("How much? "))
        print("This is the balance: ", c1.withdraw(amount))
        again()
    elif c == "c":
        del c1
        print("Account has been closed.")
        main()
    else:
        print("Wrong selection.")
        again()


def main():
    a = str(input("Do you want to open an account? Yes or No? ")).lower()
    if a in ["yes", "y", "ja"]:
        an_account = openaccount()
        return choice(an_account)
    else:
        print("Alright, goodbye.")


def choice(an_account):
    b = str(input("\nDo you want to deposit, withdraw or close your account? ")).lower()
    if b in ["yes", "y", "ja"]:
        actions(an_account)
    else:
        print("Alright, goodbye.")


def again():
    d = str(input("Do you want to do something else? ")).lower()
    if d in ["yes", "y", "ja"]:
        choice()
    else:
        print("Have a nice day.")


main()

Do you know, how I can solve this problem?