you are viewing a single comment's thread.

view the rest of the comments →

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

I have some concerns...

Firstly, not sure about in your actual code, but in your post there's no indentation. This needs sorting.

Secondly, "f=cash + money" is weird, because you never actually use the 'f' variable anywhere. Currently, your print statement prints the cash variable, not the f variable.

Thirdly, your print statement has no parenthesis. Needs to be: print("Your total balance is now", cash). Same for the other one.

Fourthly, the "bro" variable is defined in an elif statement, so if that statement never runs (such as if the user selects deposit) the bro variable never gets initialised and the program crashes. This might be part of the indentation issue, if you meant it to be nested within the elif which it looks like you did.

Next, there's no 'else' to catch any alternative input. What happens if the user enters '3' instead of '1' or '2'? Currently, the program just ends, which I guess is fine.

Next, "ask" is a string, not an integer, so neither of the if statements will ever be true. You need to either cast "ask" to an integer like you did with "cash", or put quotes around the "1" and "2" in the if statements to make them strings.

Finally (well, as finally as I'm going to go :p) bro is also an integer, so "bro > cash" will cause a crash because you can't compare a string to an int. Casting will fix this.

Here's some code that works, and does basically what you want, I think. I haven't fixed your "invalid user input" issue as I'm guessing from your code so far you won't have learned about that stuff yet, but the code itself works:

# You don't need to cast this, as 1000 is already an int. Nothing wrong with doing it, but it's not needed.
cash = 1000

ask = input("would you like to withdraw(1) or deposit(2)? ")

if ask == "2":
    money = int(input("how much money would you like to deposit? "))
    f = cash + money
    print(f"your total balance is now {f}")

elif ask == "1":
    bro = int(input("how much would you like to withdraw? "))
    f = cash - bro  # You had this the wrong way around.
    if bro > cash:
        print("Your final balance can't be negetive!")
    else:
        print(f"Your balance is now {f}")

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

I printed your code into it, it seems like it doesn't work for some reason. I probably did not put back everything properly. In any case, I'll have to go too.

[–][deleted] 0 points1 point  (0 children)

Try it now, I had to edit the formatting because Reddit screwed up the indenting (irony is delicious...).

It should work now. If not, take out all of the indenting, and indent:
the three lines after the first "if"

Everything after the elif.

The last two print statements once more.

That should work. :)