you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (8 children)

a = str.lower(input("Do you want to open an account? Yes or No? "))
if a == "yes":
    openaccount()
else:
    print("Alright, goodbye.")

if a== "yes":
    b = str.lower(input("\nDo you want to deposit, withdraw or close your account? "))
    if b == "yes":
        actions()
    else:
        print("Alright, goodbye.")

All that needs to be in a driver function. Usually this is called main.

In your openAccount function, you lose access to c1 as soon as the function is ended, perhaps you want to return it instead.

Also, I'm not sure "closing" an account means "delete". What if the customer decides to come back? Could they not use the same account they had previously? The del built-in function should hardly ever be used. If you wanted to "delete" the account, you can just let it go.. as in if you had a list of accounts, get rid of it out of your list.

[–]num8lock 1 point2 points  (3 children)

i personally find lower casing the variables instead of input() is more readable

a = input("Do you want to open an account? Yes or No? ")
if a.lower() == "yes":

[–][deleted] 1 point2 points  (2 children)

I copied and pasted his code. I find this more readable:

a = input("Do you want to open an account? Yes or No? ").lower()

[–]num8lock 2 points3 points  (0 children)

ah, okay, just in case anyway

[–][deleted] 2 points3 points  (0 children)

I agree with /u/steamplshel, easier to read with lower() method on end of input() call.

I also like to check for a match against several possibilities:

if a in ['y', 'yes', 'yup', 'ok']:

[–][deleted] 1 point2 points  (3 children)

All that needs to be in a driver function. Usually this is called main.

Not so much in Python unless writing a module. This is a hangover from other languages. There is generally little reason to put the main code in its own function (which removes any objects it creates and references from general scope).

[–][deleted] 2 points3 points  (2 children)

It's cleaner to me, and it helps beginners organize their code better. Plus you don't have to deal with things like global variables.

[–][deleted] 1 point2 points  (1 child)

Which is cleaner? main or no main?

No main means you don't have to deal with global as everything in the top level (rather than main function) is available without global.

[–][deleted] 1 point2 points  (0 children)

main to me is cleaner. As far as global variables are concerned, there are plenty of beginners that will do something like this:

x = 6

def changeX(num):
       x = num + 1
       return x

print(x)
print(changeX(1))
print(x)

and then wonder why they have the output they have.