Can anyone tell me what's wrong with this code please? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

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

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

16th Sep 2021, 9:03 PM
Emma Cooke
10 Answers
+ 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
16th Sep 2021, 9:11 PM
PresidentOfYes12
PresidentOfYes12 - avatar
+ 1
The problem is indentation for (if) your code Should be like this if condition: statement 🚫 not if condition: statement
18th Sep 2021, 7:50 PM
Sajjad
Sajjad - avatar
0
Emma, Please next time tag a relevant language, for context clarity ... https://code.sololearn.com/W3uiji9X28C1/?ref=app
17th Sep 2021, 12:40 AM
Ipang
0
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 : )
17th Sep 2021, 5:26 AM
ANUJ
ANUJ - avatar
0
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?
17th Sep 2021, 2:29 PM
PresidentOfYes12
PresidentOfYes12 - avatar
- 1
# 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
17th Sep 2021, 1:32 AM
Abhishek Kumar
Abhishek Kumar - avatar
- 1
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.
17th Sep 2021, 2:25 PM
Emma Cooke
- 1
Code coach? I'm using python. Sorry I'm new to this so unfamiliar with the terms.
17th Sep 2021, 2:34 PM
Emma Cooke
- 1
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.🤗
17th Sep 2021, 2:59 PM
Utkarsh Mishra
Utkarsh Mishra - avatar
- 1
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
17th Sep 2021, 3:49 PM
Kittu
Kittu - avatar