Beginners python programming, flow control practice

So during a practice exercise in python flow control, i was asked the following.

write a function called account_withdraw that takes two arguments, balance and amount. If amount is less or equal to than balance, the function should reutrn the remaining balance, balance - amount. If amount is greater than balance, the function should return the exact string:“you have insufficient funds”.

I’m having trouble with typing this one out correctly & have basically given up.

You can paste your code here (remember to format with </>) and ask about specific points where you think it’s not going how you want it. People can give constructive criticism/analysis this way.

Welcome to the forums :slight_smile:

I am having issues as well with the problem

I have tried to type this but I do not knoe why this doesn’t work

amount = 300;

 balance = 150;

def account_withdrawn(balance, amount):

 

   return balance - amount

  

if(amount > balance):

 print("You have insufficient funds");

I do not know how to make this work

Hi @arturvzla,

There’s a couple of things happening here.

  • the function account_withdrawn() right now is only returning a hypothetical remaining balance. You have to explicitly change the balance in the function for a change to take place.
    Example: number_to_be_changed = number_to_be_changed + modifying number.

  • Putting the conditional outside of the function might not be what you want. The question is, does this condition need to be asked if you are not withdrawing from the account?

does this condition need to be asked if you are not withdrawing from the account? I wouldn´t be so sure what you mean here, the thing is that I realized that most of the problems were of indexation the idea was to produce a function that prints

You have insufficient funds

So far I finally manage to solve it

I’m saying that that specific condition is running without the function as it is.

This is an example parallel to yours to highlight what I’m saying (notice the indentation):

def say_hello():
  print("hello")

print("hello")

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.