<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Below this line, add a link to the EXACT exercise that you are stuck at.>
I am trying to create a troubleshooting program for phones and tablets. I try to allow user inputs to call a list object, but when I enter an input, an error states that the list is not callable.
This is part of my code:
Phone = ["P", "Phone", "p", "phone", "fone", "Fone", "PHONE"]
Tablet = ['T', 'Tab', 'Tablet', 't', 'tablet', 'TABLET', 'tab']
sol_1 = ("Hold the power button until the device vibrates and/or the screen is on.")
def question():
mobile = raw_input('What mobile device are you using that has a problem? A phone or a tablet?\t')
while mobile not in Phone() or Tablet():
print(sol_1)
else:
mobile = None
mobile = raw_input("Please enter 'P' or 'T'\t")
question()
<In what way does your code behave incorrectly? Include ALL error messages.>
This is the error I get when I call a list:
Traceback (most recent call last):
File âG:/JavaScript Tasks/A453/Troubleshooting Program (No. 2).pyâ, line 32, in
question()
File âG:/JavaScript Tasks/A453/Troubleshooting Program (No. 2).pyâ, line 25, in question
while mobile not in Phone() or Tablet():
TypeError: âlistâ object is not callable
<What do you expect to happen instead?>
I want to keep the while loop input validation, but I donât know how to fix it. Can anyone help me please?
There you go my friendâŚlet me know if does what you are aiming for.
Phone = ["P", "Phone", "p", "phone", "fone", "Fone", "PHONE"]
Tablet = ['T', 'Tab', 'Tablet', 't', 'tablet', 'TABLET', 'tab']
sol_1 = ("Hold the power button until the device vibrates and/or the screen is on.")
def question():
mobile = raw_input('What mobile device are you using?\nEnter P for phone or T for tablet')
mobile = mobile.upper()
if mobile == "P" or mobile == "T":
print sol_1
return
else:
print mobile + " is not valid.\nTry again..."
return question()
question()
Sorry I forgot to delete your Phone and Tablet lists. But I tested it and it works, it will not stop asking the user until the user input the valid values.
A list is a data structure, it supports a couple of operations such as looking up a value by index or appending at the end or iterating through it. An operation that is not supported is calling it, what would that mean anyway? What would executing a list do?
Also note that while-else doesnât make much sense without a break, because without a break the else-block will always execute, just as if you had just placed it below the while-loop without the else.
And here:
mobile = None
mobile = raw_input("Please enter 'P' or 'T'\t")
Why assign None to your variable only to immediately overwrite it? the first line there has no effect.
Then thereâs this:
mobile not in Phone() or Tablet()
or has no magical interaction that causes ânot inâ to consider both Phone() and Tablet() as containing mobile â this isnât English where you can say âis the ball one of blue or purpleâ? You have to test if itâs blue and then test if itâs purple
At the end of the troubleshooting process, the program will loop back to the beginning to ask the user if they have another problem, thatâs why âmobile = Noneâ is there.
As for the while condition, thanks, I just realized that now.