Can anyone tell me what's wrong with this code please? | Sololearn: Learn to code for FREE!

+3

Can anyone tell me what's wrong with this code please?

Incorrect code https://code.sololearn.com/cc0HTQd1Brno/?ref=app

9/16/2021 9:03:30 PM

Emma Cooke

10 Answers

New Answer

+2

The indentation needs to be fixed, and you have to change "=" to "in" to find whether the input is in the array. Also, instead of doing "elif not:", which is invalid syntax, you can just do "else:", or "elif x not in commands". https://code.sololearn.com/cb1kXpm2WLPX/?ref=app

+1

Emma, Please next time tag a relevant language, for context clarity ... https://code.sololearn.com/W3uiji9X28C1/?ref=app

+1

WELL Emma, I tell you lists are complicated, so we can use if, else. Here I have modified the code according to you, FRIEND : ) Here's the link - https://code.sololearn.com/cN8hdN8R9Uvn HOPE IT HELPS EMMA : )

+1

Maybe add ".lower()" to all the references to the variable "x", except its definition. That way, you wouldn't have to make everything capitalized. Also, which code coach problem is this a part of?

+1

The problem is indentation for (if) your code Should be like this if condition: statement 🚫 not if condition: statement

0

# Created by Abhishek kumar commands = ["Lights Off", "Lock the door", "Open the door", "Make Coffee", "Shut down"] x = input() if x in commands: print("OK") else: print("not supported") https://code.sololearn.com/czrLjtk9cG26

0

Hi, these are great thanks. But it's not resolving the problem completely. There are 5 test cases, and only 3 of them are being ticked green whilst 2 remain with crosses against them. So it still keeps telling me to try again. Not really sure what else it wants me to do.

0

Code coach? I'm using python. Sorry I'm new to this so unfamiliar with the terms.

0

Bro, always try to write the code while keeping the indentation in mind. Not only it will provide neatness but also help you in exploring the blocks but also help others to understand it better.🤗

0

There's indentation mistake and you are assigning values to the list in if condition which is wrong And "not" is k Reserved word If you wanted to use not the use it like. Syntax: if <var> not in <sequence>: https://code.sololearn.com/clwgHblnR4pg/?ref=app