Python Code Classes and Functions

What is wrong the following code? Python returns “False” instead of “Bob eats pancakes.” when I run it.

class Person:
    def __init__(self, is_hungry, favorite_food, name):
        self.is_hungry = is_hungry
        self.favorite_food = favorite_food
        self.name = name



bob = Person(True, "Pancakes", "Bob")


def hungry(p):
    # enter something with the class Person
    if type(p) == Person:
        if p.is_hungry:
            print(p.name + " eats " + p.favorite_food)
        else:
            print(p.name + " is not hungry.")


print(hungry(bob))

@RexRode Your code works on my computer. One tip, you need to return out of the function not print because you wrapped the function in a print statement to run it.

[.....]

emma = Person(True, "kale", "Emma")
edgar = Person(False, 'avocado', "Edgar")

def hungry(p):
    # enter something with the class Person
    if type(p) == Person:
        if p.is_hungry:
            return p.name + " eats " + p.favorite_food
        else:
            return p.name + " is not hungry."

print(hungry(emma))
print(hungry(edgar))

Output:

Emma eats kale.
Edgar is not hungry.

I was using PyCharm and was used to looking at the bottom of the output window for the expected result but forget to look at the top of the output window.

You might want to try a simple text editor. I find that they are the best for learning to code. Those IDEs do too much automation for the programmer. Notepad++ is simple and works well, Atom is pretty good. I tried PyCharm once and went running back to Vim.

What is Vim? I have Atom installed on my computer and really like it.

@RexRode Vim came from an editor called Vi that was created in 1976. There are many, many reasons why people enjoy using it.
After a person installs it, it is recommended to run the command vimtutor to learn how to move around.

You can read this link to get more information and the history of how it all began more than 4 decades ago:

Vi Editor - Why Programmers Still Think This Old Editor Is Still Awesome

Creating a .vimrc file is a good idea too. Here is my vimrc.