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
keep Spathiphyllum within quotes
like:-
if plant == âspathiphyllumâ:
Thanks for the update sir will keep it mind
The whole code
should be:
plant = input("enter plant: ")
if plant == âSpathiphyllumâ:
print (âYes - Spathiphyllum is the best plant ever!â)
elif plant == âspathiphyllumâ:
print (âNo, I want a big Spathiphyllum!â)
elif plant == âpelargoniumâ:
print (âSpathiphyllum! Not pelargonium!â)
else:
print(âSpathiphyllum! Not [input]!â)
@index, itâs great that you know how to solve this, but we try to help folks fix their code and build their understanding rather than just giving them code.
Thanks
print(âSpathiphyllum! Not [input]!â)
This line is giving output as below:
enter plant: dd
Spathiphyllum! Not [input]!
Can you check what is wrong below:
plant = input("enter plant: ")
if plant == âSpathiphyllumâ:
print (âYes - Spathiphyllum is the best plant ever!â)
elif plant == âspathiphyllumâ:
print (âNo, I want a big Spathiphyllum!â)
else:
print(âSpathiphyllum! Not [input]!â)