Inquiry regarding Python function.

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

def deposit(balance, money):
    print("Deposit Completed" The balance is {} won."format(balance + money))
    # # return balance + money

def withdraw(balance, money):
    if balance >= money:
        print("Withdrawal completed. The balance is {} won."format(balance - money))
        return balance - money
    else:
        print("Insufficient balance". The balance is {} won."format(balance))
        return balance

balance = 0
balance = deposit(balance, 1000)
balance = withdraw(balance, 2000)

If I run it, I see the error below, what's wrong?

Traceback (most recent call last):
  File "c:\Users\User\Desktop\PythonWorkspace\practice.py", line 848, in <module>
    balance = withdraw(balance, 2000)
  File "c:\Users\User\Desktop\PythonWorkspace\practice.py", line 839, in withdraw
    if balance >= money:
TypeError: '>=' not supported between instances of 'NoneType' and 'int'

python

2022-09-20 10:55

1 Answers

balance = deposit(balance, 1000)

What would the balance be here? None. So the error says, "You cannot compare the None type with the int type with the >= operator."

You only need to correct one line, but it seems like the assignment given to the questioner to figure out what it is. Think about it.


2022-09-20 10:55

If you have any answers or tips


© 2022 pinfo. All rights reserved.