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


i've read on 50 posts similar title, , have yet answer question. wrong call loop start? i'm using python 2.7.7

def skill():      global pskill     global fee      skill = input ("please enter skill level - must either enter <c> casual or <e> expert!!")      if skill == "c" or skill == "c":         pskill = "casual"         fee = 30      elif skill == "e" or skill == "e":         pskill = "expert"         fee = 45      else:         print("sorry don't recognise answer - please enter answer again")         skill() 

and further down have piece of code won't work when earlier error.

totalfee = float(rate) * float(fee) totalfee = str(totalfee) 

the error is...

traceback (most recent call last): line 106, in <module> main() line 93, in main main() line 68, in main currency() typeerror: 'str' object not callable 

you've redefined symbol skill within function skill. change name of 1 of those. instance:

level = input ("please enter skill level - must either enter <c> casual or <e> expert!!")  if level == "c" or level == "c":     pskill = "casual"     fee = 30  elif level == "e" or level == "e":     pskill = "expert"     fee = 45 

now, when try recur on skill, name still refers function, not local variable.


additional problem:

you should use while loop input until valid one. recursion adds garbage run-time stack.

level = "" while level not in "ccee":     skill = input ("please enter skill level - must either enter <c> casual or <e> expert!!") 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -