+ 1
"Just Say It" SoloLearn List exercise
I am having trouble with the List exercise. I have made multiple attempts to satisfy all conditions, but to no avail, I have failed. I was hoping to get some help from another beginner and simply explain what mistake I was making. My code: https://code.sololearn.com/cA14A21A009A Exercise: https://www.sololearn.com/codecoach/1042?language=py&location=2&source=profile
16 Antworten
+ 4
Try to solve using if-else statement.
+ 4
I’m confused as this code outputs the correct respnse but fails the test cases. It works in the playground with no errors.
commands = ["Lights Off", "Lock the door", "Open the door", "Make Coffee", "Shut down"]
#your code goes here
voice = input()
if voice in commands:
print ("Ok")
else:
print ("Not Supported")
+ 2
∆BH∆Y well, I think there's a bug...
When I logged in to my Sololearn account in my laptop and clicked the link, it just displays the question!
Well, here's the question!
List Operations
You're making a voice recognition system.
The supported commands are stored in a list.
Complete the program to take a command as input, check if it's supported and output "OK" if it is, and "Not supported", if not.
Sample Input
Lights Off
Sample Output
OK
And here's the list!
Lights Off, Lock the door, Open the door, Make Coffee, Shut down
+ 2
This worked for me
list1 = ['Lights Off', 'Lock the door', 'Open the door', 'Make Coffee', 'Shut down']
input1 = input()
if input1 in list1:
print('OK')
else:
print("Not supported")
+ 2
Geoff Ross,
It looks like you may have failed test cases because "Ok" is not set to "OK" as in the instructions. Fixing that should pass all test cases.
I know this response is coming months after your post, so you have probably moved on from this question. Either way I hope you were able to remedy the problem and move foward.
-Keven
+ 1
Here is the answer to the project!
commands = ["Lights Off", "Lock the door", "Open the door", "Make Coffee", "Shut down"]
command = (input)()
if command in commands:
print("OK")
else:
print("Not supported")
0
You can try to iterate the elements in the list and see if the input is in the commands list!
commands = ["Lights Off", "Lock the door", "Open the door", "Make Coffee", "Shut down"]
i = input()
b = False
for command in commands:
if i == command:
b = True
if b == True:
print("OK")
else:
print("Not supported")
Hope it works! Happy programming :)
0
∆BH∆Y ,
I ended up looking at your code, and at one point, I had something similar. The only difference was I did not ask for the input. So the variable stayed fixed. I thank you all for the responses!
Sincerely,
Matt
0
commands = ["Lights Off", "Lock the door", "Open the door", "Make Coffee", "Shut down"]
#your code goes here
command = input()
if command in commands:
print("OK")
else:
("Not supported")
0
commands = ["Lights Off", "Lock the door", "Open the door", "Make Coffee", "Shut down"]
#your code goes here
x=input()
if x not in commands :
print("Not supported")
else:
print("OK")
0
Here is my simple and easy to understand solution:
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")
0
I just used if-else statement
commands = ["Lights Off", "Lock the door", "Open the door", "Make Coffee", "Shut down"]
if "Lights Off" in commands:
print("OK")
else:
print("Not Supported")
0
i used if and elifs and confirmed that the code still works if you replace elif with else. i just wanted to implement using 'in' and 'not'
c=["lights off","lock the door","open the door","make coffee", "shutdown"]
cmd=input("command daze: "))
if cmd not in c:
print("Not supported")
elif cmd in c:
print("OK")
0
commands = ["Lights Off", "Lock the door", "Open the door", "Make Coffee", "Shut down"]
txt = input()
if txt in commands:
print("OK")
else:
print("Not supported")
0
"""
List Operations
You’re making a voice recognition system.
The supported commands are stored in a list.
Complete the program to take a command as input, check if it’s supported and output "OK", if it is, and "Not supported", if not.
Sample Input
Lights Off
Sample Output
OK
"""
commands = ["Lights Off", "Lock the door", "Open the door", "Make Coffee", "Shut down"]
#your code goes here
command = input()
if command in commands:
print("OK")
else:
print("Not supported")
0
a=input()
commands = ["Lights Off", "Lock the door", "Open the door", "Make Coffee", "Shut down"]
if (a in commands ):
print ("ok")
elif (a not in commands ):
print ("not supported")