TypeError: 'str' object is not callable with if statement

382
April 08, 2017, at 06:08 AM

I've read over 50 posts with similar title, and have yet to answer my question. What is wrong with my call to loop back to the start? I'm using Python 2.7.7

def Skill():
    global PSkill
    global Fee
    Skill = input ("Please enter your skill level - you must either enter <C> for casual or <E> for expert!!")
    if Skill == "C" or Skill == "c":
        PSkill = "Casual"
        Fee = 30
    elif Skill == "E" or Skill == "e":
        PSkill = "Expert"
        Fee = 45
    else:
        print("Sorry I don't recognise that answer - please enter the answer again")
        Skill()

And further down i have this piece of code which won't work when their was an earlier error.

TotalFee = float(Rate) * float(Fee)
TotalFee = str(TotalFee)

The error which I then get is...

Traceback (most recent call last):
line 106, in <module>
Main()
line 93, in Main
Main()
line 68, in Main
Currency()
TypeError: 'str' object is not callable
Answer 1

You've redefined the symbol Skill within the function Skill. Change the name of one of those. For instance:

level = input ("Please enter your skill level - you must either enter <C> for casual or <E> for expert!!")
if level == "C" or level == "c":
    PSkill = "Casual"
    Fee = 30
elif level == "E" or level == "e":
    PSkill = "Expert"
    Fee = 45

Now, when you try to recur on Skill, that name still refers to the function, not the local variable.

Additional problem:

You should use a while loop to get input until you get a valid one. Recursion adds garbage to the run-time stack.

level = ""
while level not in "CcEe":
    Skill = input ("Please enter your skill level - you must either enter <C> for casual or <E> for expert!!")
Rent Charter Buses Company
READ ALSO
FileSharing using UDP in python

FileSharing using UDP in python

I am brand new to networking and its been years since Ive coded in pythonI'm trying to create a program that will do the following:

426
How to implement a toolstrip to my GUI?

How to implement a toolstrip to my GUI?

I am creating a simple application to manage unknown words when learning a new languageThe application is written in Python and I am using Tkinter to build the GUI

364
How to write two variables in one line? [duplicate]

How to write two variables in one line? [duplicate]

This question already has an answer here:

398
Bokeh: Making the x_range.start and x_range.end update on_change

Bokeh: Making the x_range.start and x_range.end update on_change

I have been experimenting with bokeh for a while, but for some reason I am not able to figure out how to update the x-axis range (its start and end points), I know by default it does this (update), but I want to define the values manuallyNOTE: When I try to define...

580