List object error, While Loop

<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()
2 Likes

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.

Thanks a lot for your help. It works! :slight_smile:
The only thing is I really wanted variation in my code, so I wanted to keep the while loop, but oh well.

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

1 Like

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. :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.