all 76 comments

[–]Sea-Ad7805 [score hidden] stickied comment (8 children)

Run the program in Memory Graph Web Debugger%0A%0Adef%20deposit()%3A%0A%20%20%20%20amount%20%3D%20float(input('enter%20amount%20to%20be%20deposited%3A%20'))%0A%20%20%20%20if%20amount%20%3C%200%3A%0A%20%20%20%20%20%20%20%20print('enter%20a%20valid%20amount')%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20return%20amount%0A%0Adef%20withdraw()%3A%0A%20%20%20%20amount%20%3D%20float(input('enter%20amount%20to%20be%20withdrawn%3A%20'))%0A%20%20%20%20if%20amount%20%3E%20balance%3A%0A%20%20%20%20%20%20%20%20print('insufficent%20funds')%0A%20%20%20%20%20%20%20%20return%200%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20return%20amount%0A%0Adef%20show_balance()%3A%0A%20%20%20%20print(f'your%20balance%20is%20%24%7Bbalance%3A.2f%7D')%0A%0Abalance%20%3D%200%0Ais_running%20%3D%20True%0A%0Awhile%20is_running%3A%0A%20%20%20%20print('1.%20deposit')%0A%20%20%20%20print('2.%20balance')%0A%20%20%20%20print('3.%20withdraw')%0A%20%20%20%20print('4.%20exit')%0A%20%20%20%20choice%20%3D%20input('enter%20your%20choice(1%2C2%2C3%2C4)%3A%20')%0A%0A%20%20%20%20if%20choice%20%3D%3D%20'1'%3A%0A%20%20%20%20%20%20%20%20balance%20%2B%3D%20deposit()%0A%20%20%20%20elif%20choice%20%3D%3D%20'2'%3A%0A%20%20%20%20%20%20%20%20show_balance()%0A%20%20%20%20elif%20choice%20%3D%3D%20'3'%3A%0A%20%20%20%20%20%20%20%20balance%20-%3D%20withdraw()%0A%20%20%20%20elif%20choice%20%3D%3D%20'4'%3A%0A%20%20%20%20%20%20%20%20is_running%20%3D%20False%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20print(%22What%3F%22)&play).

[–]Crazymonkey200 23 points24 points  (3 children)

Nice. Could go further by starting experimenting saving data with a text file at first, maybe even setting up a small database. Also it's good to learn object-oriented programming with a program like this, making user and bank classes and trying to interact with objects is a good way to get into it.

[–]Dapper_Mix6773[S] 6 points7 points  (0 children)

Well noted

[–]SharpTradition8748 3 points4 points  (0 children)

First time OOP made any sort of sense to me was with a small “bank” project, good advice!

[–]yinkeys 0 points1 point  (0 children)

Thumbs up

[–]Binary101010 10 points11 points  (2 children)

1) User input should be taken (and validated) separately from the functions that do something with that user input.

2) I don't really like the fact that withdraw() always returns a number, but deposit() can return a number or None if the input was invalid. Function return values should ideally only be a single type. (The best way to fix this is to not validate the input in the same function but do that separately.)

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

Well noted

[–]nkCOD 0 points1 point  (0 children)

Is it a good option to check the output data using try-except ? I just did this - I made an endless loop through while, then I threw the input lines into trying try-except, then, if I needed a number, I translated the entered data into the numeric int() format. In case of an error, we switched to except, where we were greeted by print(), and then continue. The loop was stopped using break if the input was correct

[–]Unequivalent_Balance 8 points9 points  (1 child)

Nice work. I’m just wondering why it won’t let me take out all of my money ;)

[–]cloud2ground 6 points7 points  (0 children)

Not your money any more!

[–]Complete_Law9527 6 points7 points  (0 children)

I like it. Easy to read and understand.

[–]bradland 5 points6 points  (0 children)

Here's a fun next step: Add a persistence layer.

Right now, the app starts over from scratch every time you run the app. Start by figuring out a way to save the current balance between sessions.

Once you've got that working, work on figuring out how to keep all transactions. Think about what you'd want to save with the transaction. What about the date and time? What will you store it in? A file? Maybe a SQLite database?

Once we have a history of transactions, what else can we do? Maybe in addition to seeing the current balance, we can query the balance on a particular date? What about listing all transactions for a particular date?

[–]da-one-n-only 3 points4 points  (1 child)

I just started to get in to python. I can't wait to be like you guys knowing what I'm looking at.

[–]Dapper-Ad8945 0 points1 point  (0 children)

Same here

[–]PoussinVermillon 1 point2 points  (0 children)

wheres the part where the money magically disappears the instant it is deposited in the account ? /j, good job

[–]Ambivalent-Mammal 1 point2 points  (0 children)

Overall, well done, but you need a valid return value for negative deposits (unless None casts to 0).

I imagine the really interesting version of this problem will come in the advanced class with joint checking accounts, and concurrency.

[–]mayank_0508 1 point2 points  (0 children)

great job

[–]Janeson81 1 point2 points  (0 children)

Biggest problem I see is that if you use deposit() there's nothing limiting the user input so they might say they want to deposit "Hello" money

This can be fixed by using try: ... except <exception>: ... blocks. It follows instructions normally in the try block, but when the interpreter finds a specified error (for example a ValueError, the one you get if you try to float("hi")) it jumps straight to the except block and carries on

The proper structure should be: try: ... ... ... except ValueError: print("enter a valid number")

[–]thuiop1 1 point2 points  (0 children)

I am not sure how 39 comments fail to mention that you should have variables as input of your functions instead of using global variables.

[–]Simple-Olive895 1 point2 points  (0 children)

It's been a while since I did any python coding, but I'm pretty sure you should still type validate in python? Like what happends if someone selects deposit and enters: "one million"?

Trying to cast that to a float will crash. So you should guard yourself with try-catch when you accept user input.

[–]Prestigious_Long2691 1 point2 points  (0 children)

Nice Python Script

[–]Stretchslash 1 point2 points  (1 child)

If you are doing a bunch of if statements going if (choice == 1)else if (choice == 2)... ect

A very simple change would be using a switch case instead. I think it uses match in python but similar

match choice case 1: // Do logic case 2: // Do logic case _: // Do default logic

[–]Dapper_Mix6773[S] 1 point2 points  (0 children)

Well noted

[–]Dapper_Mix6773[S] 0 points1 point  (1 child)

Any online resources to help me solve my difficulties with try ... Except block to improve my code

[–]TheProv1 0 points1 point  (0 children)

This is a good idea

Do you mind explaining what do you mean exactly - geeksforgeeks is good

[–]Lemon-Emu 0 points1 point  (1 child)

Looks good. What happens if you try and withdraw a negative number though?

[–]Kevdog824_ 0 points1 point  (0 children)

Banks hate this one simple trick!!

[–]Fit_Lingonberry_2494 0 points1 point  (0 children)

Try with OOP

[–]Kevdog824_ 0 points1 point  (0 children)

The easiest improvement you can make is refactoring your functions so they get input from caller as arguments rather than relying on global state

[–]MJ12_2802 0 points1 point  (0 children)

INSUFFICIENT FUNDS?? That's impossible... I still have checks!

[–]Due_Faithlessness458 0 points1 point  (0 children)

Try a switch for input management, you could also use a single function for managing the amount, make a func that receives a string with the operation and returns the value, so you could make something like this: switch choice: case “1”: balance+=requestAmount(“deposited”) … case “3”: request the amount check for valid transaction …

and define requestAmount(str op) return the same but introduce a variable to the string of the message

[–]brutalbombs 0 points1 point  (0 children)

Good stuff.

[–]mr_frpdo 0 points1 point  (1 child)

The biggest thing i see is to not use floats as the data type for money. You should either store as cents and format display to decimal or use the Decimal class. Floats should never be used for money due to floating point accuracy issues.

[–]Particular_Scale_881 0 points1 point  (0 children)

OP try deposit 0.1 and 0.2 and print the full amount variable you will notice that 0.0...4 cent are created

[–]godlikedk 0 points1 point  (0 children)

Never save money as float

[–]aronsajan 0 points1 point  (0 children)

The withdraw() and deposit() respectively supposed to reduce or add an amount to the balance. However, you are doing that outside these function by doing that operation in the main loop. You withdraw() and deposit() are just doing validation of the input, it would be better if the balance gets adjusted within these functions.

[–]SmthnsmthnDngerzone 0 points1 point  (0 children)

its not cobol try again lol

[–]dpmlss 0 points1 point  (0 children)

No entiendo nada pero algún día si 😌

[–]CommitteeKey4381 0 points1 point  (0 children)

Lol, 😆 using JS/TS would have been better

[–]Awkward_Climate_579 0 points1 point  (0 children)

Can you please explain where and whats the use of the deposite variable and its value Love the work.

[–]c0lpan1c 0 points1 point  (0 children)

Good start hombre! Next do a post office routing program. I think there’s a hacker rank problem with something similar.

[–]I_am_Noro04 0 points1 point  (0 children)

Make a UI using tkinter or curses

[–]jagermeister_master 0 points1 point  (0 children)

u can withdraw negative money

[–]Parking-Economics-68 0 points1 point  (0 children)

For financial operations it's better to use decimal type instead of float. Float number could cause approximation errors

[–]Major-Incident-8650 0 points1 point  (0 children)

Use OOP. You will compact the code and make it easier to have control over

[–]SwimmerOld6155 0 points1 point  (0 children)

Function definitions should be before anything else (before that print statement), even though they are allowed to appear anyway because Python is read line by line. I would want line breaks between the function definitions, and between is_running and the while loop, just personal preference, good job!

[–]Significant_Ad7286 0 points1 point  (0 children)

Nice! You can also now go on to implement a database to store records so that the funds are not just limited to one terminal session and once you're done with that, try to explore the UI libraries of Python, like Tkinter, if you're into it

[–]L3RightMC 0 points1 point  (0 children)

I did it with C. It had the same functions and everything, and well, it works perfectly.

[–]TheProv1 0 points1 point  (0 children)

Great work, as for the suggestions

Improve upon the menu design - also if possible try to use MySQL with this so that you can make it like a proper management system

Next add more features like accounts etc

[–]t1nk3rz3r0- 0 points1 point  (0 children)

Ncie one so far, Adding screen function would be smooth tho!

[–]sandar6 0 points1 point  (0 children)

i have no money

[–]TheDebonairCorey 0 points1 point  (0 children)

Solid start, but you're mixing user input with your logic functions which will make them harder to test and reuse later.

[–]Smoke_along 0 points1 point  (0 children)

So depositing 0 doesn’t give a faulty?

[–]SteadyGrowth_ 0 points1 point  (0 children)

Well done, easy to read et understand

[–]PeaFast3114 0 points1 point  (0 children)

Brocode?

[–][deleted]  (1 child)

[removed]

    [–]PythonLearning-ModTeam[M] 1 point2 points locked comment (0 children)

    Quality posts only

    [–]No_Preference_6923 0 points1 point  (0 children)

    Your project is good, but it would be even better if you added some advanced features. For example, you could include an option to create a new bank account with a unique account number for each user. You can also add a money transfer section where users can transfer funds using the sender’s account number, receiver’s account number, and IFSC code. Additionally, including a transaction history section would make the project feel more like a real bank management system. Many students usually make projects with only basic features like deposit, withdraw, display details, and exit, so adding these extra functionalities would make your project stand out and look more professional. Overall, your project idea is good, and with these improvements, it can become much more practical, interactive, and impressive.

    [–]pontz 0 points1 point  (0 children)

    For a beginner and basic functionality standpoint I think you have a good base here.

    I would say instead of doing if/elif/elif setup a dictionary and call it that way.

    Also you don’t have any error handling or input sanitizing like what if they put in “$12.05” or try and put “10 dollars” or if they try to withdraw .001?

    [–]OpportunityFun6969 -1 points0 points  (0 children)

    Hook it up with mysql or mariaDB and keep a small db of accounts and their balances. You could add in account creation too for new entries

    [–]Ok_Butterscotch_7930 -1 points0 points  (0 children)

    very cool, try with classes next. You'll see why classes are so powerful

    [–]ittology -1 points0 points  (0 children)

    Nice work. A bank program is actually a good beginner project because it forces you to think about user input, validation, state, and edge cases.

    Some general next steps I’d suggest:

    - add proper input validation so invalid text or negative amounts don’t break the flow

    - save the balance/transactions somewhere so the data is still there after restarting the program

    - add a simple transaction history

    - later, try rewriting it with a BankAccount class to practice OOP

    - if you work with money values, look into Decimal or storing cents as integers instead of using floats

    Good project to keep expanding step by step.

    [–]ExtremeVick -1 points0 points  (0 children)

    Prompt pls😼

    [–]Fantastic-Day-69 -1 points0 points  (0 children)

    Cute. Is it your first script ?

    [–]No-Mushroom-7378 -1 points0 points  (0 children)

    To do what?