Reputation: 53
I need help making a program that functions as a remote control. I'm not sure how to make a list from the different options that the user can choose. And then if it's not right just keep asking until the user powers the TV off. And it keeps giving me indentation errors, I need some advice with what I'm doing wrong, maybe some formatting and help simplifying my code but with nothing too advanced since I'm on my first semester of CS. It's basically def/return, while/for loops, and if/elif/else statements. Below is my code and directions (that I don't understand too well)
Code
op1 =print ("'P' or 'p' Turns the power on")
op2 =print ("‘1’,’2’,’3’,’4’,’5’ Set a channel to the specified number")
op3 =print ("‘C+’ or ‘c+’ Add one to the current channel number")
op4 =print ("‘C-’ or ‘c-’ Subtract one to the current channel number")
op5 =print ("‘V+’ or ‘v+’ Add one to the current volume level")
op6 =print ("‘V-’ or ‘v-’ Subtract one from the current volume level")
op7 =print ("‘M’ or ‘m’ Mute the current volume level")
op0 =print ("‘X’ or ‘x’ Turn off the tv and exit the program")
print()
powerOff=False
channel =3
volume = 5
while powerOff !=False:
choice = input("Choose one of the above options: ")
while choice is not "x" or "X":
if choice == "x" or "X":
powerOff == True
elif choice == "P" or "p":
powerOff=False
if choice == volume and powerOff == False:
if choice == "M" or "m":
volume = 0
elif choice == "V+" or "v+":
volume+= 1
elif choice == "V-" or "v-":
volume= volume - 1
elif choice == channel and powerOff == False:
if choice == "1" or "2" or "3" or "4" or "5":
channel == choice
elif choice == "C+" or "c+":
channel += 1
elif choice == "C-" or "c-":
channel = channel - 1
else
choice == powerOff
print (choice)
choice = choice
Again, I just need advice to learn how to make this work and in a simpler way so I can apply it in the future, thanks
Upvotes: 3
Views: 1438
Reputation: 16952
There are a couple of mistakes here.
Your outer while
loop will never get executed because you start by setting powerOff
to False
.
The test if choice == "x" or "X":
doesn't do what you think it does. It needs to be if choice.upper() == "X":
or if choice in ("x","X"):
. That needs to be fixed in 9 places, including the inner while
.
Indentation is wrong in the last 2 lines: the print()
call needs to be inside the while
loop.
Assigning the value of the print()
function to op1
etc does nothing useful, beyond printing the instructions. The variables will all have the value None
.
Upvotes: 2
Reputation: 143
while(True):
X= input("enter the command")
"""do what ever you want here""""
this will always ask for a single variable and you can check with if/else. use hold if you want to hold the asking statement.
Upvotes: 0