Python Exercise

Python Exercise
0

Imagine that your computer program loves these Spathiphyllum. Whenever it receives an input in the form of the word Spathiphyllum , it involuntarily shouts to the console the following string: "Spathiphyllum is the best plant ever!"

What is your question? What have you tried so far? Do you have any code to share?

Hello Bob,
I m just beginner in python . i have written some code which are not working . can you please check following code.

plant = (input("Please enter your plant: "))
    if plant == Spathiphyllum :
        print ("Spathiphyllum is the best plant ever!")
        if plant == spathiphyllum :
        print("No, I want a big Spathiphyllum!")
        else:
        print("Spathiphyllum! Not [input]!")

Error is
File “main.py”, line 2, in
if plant == Spathiphyllum :
NameError: name ’ Spathiphyllum’ is not defined

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

Variable names are case sensitive. You set Plant variable (capitalized), while check if plant (not capitalized) has certain value.

Keep in mind too that in your code plant == Spathiphyllum compares two variables, not variable and string.

Hello Sanity,
I did realise my mistake and did it correct but new problem has been arise . can you please check that code again and guide me.
Thanks

Look at what I wrote in the second part of the post.

Hi, it’s because your indentation is off. Indentation in python is veryy important. Additionally, you didn’t put Spathiphyllum in quotes. Strings are always required to be enclosed by quotes. I’d also consider using ‘elif’ instead of a nested if but idk if the specific exercise you’re doing requires you to use nested if. Hope this helps

i changed my code like
if plant == “Spathiphyllum”
but now i cannot get any out put
please guide me

Did you change the indentation?

Yes “hmm” i changed it and i have no error message
but its not giving me any desire out put

can you share the code?

Hello Guys
with help of all reply i am able to run this code successfully.
Thanks once again

1 Like

keep Spathiphyllum within quotes
like:-
if plant == “spathiphyllum”:

Thanks for the update sir will keep it mind