0
Why do I get an error
The task : 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 My code : commands = ["Lights Off", "Lock the door", "Open the door", "Make Coffee", "Shut down"] x= str(input) if x == commands : print ("Ok") else: print ("Not supported")
5 Respuestas
+ 4
mazen mohamed
x = str(input) - What is this?
By default, the input() function already returns a string value.
if x in commands: # not ==
Sample Output: OK
You have: print("Ok")
+ 1
mazen mohamed That's because you made a bunch of mistakes in such a short code.
+ 1
Hi, mazen mohamed !
You call the builtin function input (and all other functions) with parathesis at the end, like
x = input()
You can use ’in’ to check membership, like
val in my_list
to check if the value in the variable val is in the list my_list.
+ 1
Hi , Per Bratthammar
Thanks a lot
I did it
Thanks 🙏
0
Thanks 🙏
But it's the same result
Give me not supported
Not Ok