def check_difference(machine, customer):
for key in machine:
if Counter(machine[key]) > Counter(customer[key]):
print("here is your drink")
else:
print(f"There is not enough {key}")
return machine, customer
difference = check_difference(machine_resources, users_drink)
print(difference)
print(type(difference))
```py
#๐ Why am I getting <class 'NoneType'> For the following
27 messages ยท Page 1 of 1 (latest)
@spring copper
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
you don't return anything in some cases
Meaning?
But if there isnt enough resources in the machine then it returns a dictionary
This is what your code looks like:
def check_difference(machine, customer):
for key in machine:
if Counter(machine[key]) > Counter(customer[key]):
print("here is your drink")
else:
print(f"There is not enough {key}")
return machine, customer
return None # This is implicit!
so you return only in the else branch
ohhhh I see
all functions have an invisible default return statement at the end of them, which returns None
So you'll need to override that one, and cover all executions paths, in order to have consistent returns
So is this correct:
def check_difference(machine, customer):
for key in machine:
if Counter(machine[key]) > Counter(customer[key]):
print("here is your drink")
return machine, customer
else:
print(f"There is not enough {key}")
return machine, customer
```py
From a syntactiv POV, it's correct
Functionally, it's doing the same thing in the two branches of the "if" condition
And the loop becomes useless
Ohh so if I dont specify what is retured by default it will return blank?
!e
def dosomething():
print("hello")
var = dosomething()
print(var)
@minor flare :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | hello
002 | None
Yes, have a look at the example I executed
So my for loop is irrelivant in my case?
yes, since it'll always return during the first iteration
So its irelivant becase I am already using an if statement in a function
Am I correct?
It's mostly because you're saying "if not X then ALWAYS Y"
Which doesn't leave room to your loop to move on
That makes sense
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.