1

I'm new to Python, I've looked at other code but have no idea how to remove the nonetype error from mine,

tutorial = input("Do you want to do the tutorial? 1 is yes and 0 is no, this will be the same for everything") if tutorial <1: print("That isn't valid") if tutorial>0: print("That isn't valid") if tutorial == 1: print("In battle you can use either sword, magic or items. Sword damage will be between your minimum and maximum damage, magic will be constant and can be used to heal or attack, items can be used to boost attack, restore health or armour") 

I get this error:

Traceback (most recent call last): File "<string>", line 250, in run_nodebug File "C:\Users\Bas\Desktop\Game.py", line 50, in <module> tutorial = input("Do you want to do the tutorial? 1 is yes and 0 is no, this will be the same for everything") TypeError: 'NoneType' object is not callable 

Heres the full code:

playerhealth = 100 playerlow = 10 playerhigh = 30 playerarmour = 50 playermagic = 20 level = 0 xptonextlevel = 200 itemuse = 0 rookhealth = 100 rooklow = 10 rookhigh = 20 rookarmour = 100 medichealth = 150 mediclow = 10 medichigh = 30 medicarmour = 50 rushhealth = 20 rushlow = 10 rushhigh = 10 rusharmour = 30 drillerhealth = 30 drillerlow = 50 drillerhigh = 80 drillerarmour = 20 dragonhealth = 200 dragonlow = 150 dragonhigh = 250 dragonarmour = 150 dragonmagic = 100 dragonl = 45 godhealth = 300 godlow = 250 godhigh = 350 godarmour = 250 godmagic = 200 godl = 50 magehealth = 100 magearmour = 0 magemagic = 50 magel = 10 tutorial = input("Do you want to do the tutorial? 1 is yes and 0 is no, this will be the same for everything") if tutorial <1: print("That isn't valid") if tutorial>0: print("That isn't valid") if tutorial == 1: print("In battle you can use either sword, magic or items. Sword damage will be between your minimum and maximum damage, magic will be constant and can be used to heal or attack, items can be used to boost attack, restore health or armour") se = input("Input 1 for story or 0 for endless") 
7
  • 5
    Do you have a variable called input? Commented Dec 2, 2016 at 21:48
  • 1
    Is that all your code? Because it seems like you must have done something to your input function. Maybe you assigned input to something somewhere in the rest of your code, and you ultimately are shadowing the builtin input. Commented Dec 2, 2016 at 21:49
  • @idjaw i just added all of it Commented Dec 2, 2016 at 22:02
  • @Llione Can't replicate. Something is going on in your environment. You must have done something that is still affecting your environment. Commented Dec 2, 2016 at 22:11
  • 1
    @marts: input exists in Python 2, it's just always wrong (it's equivalent to eval(input(...)) on Python 3). On Python 2, you need to use raw_input to avoid implicitly eval-ing the string entered by the user. Commented Dec 2, 2016 at 23:54

1 Answer 1

2

You get this error because the identifier input has been assigned the value None. Somewhere in your code, the following line must have been executed.

input = None 

NoneType is the type of the singleton constant None. You will get the same error if you try to do this:

>>> None("Do you want to do the tutorial?") Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'NoneType' object is not callable 

Python does not prevent you from overriding built-in functions with new values. Sometimes it can be useful to redefine for instance the function print. But in normal circumstances it's a bad idea to use input, list, int etc. as variable names, since that can cause bugs such as this one.

You can reduce the likelyhood of accidentaly overwriting an identifier by using a dictionary instead of declaring a very long list of variables.

gamestate = { 'playerhealth': 100, 'playerlow': 10, 'playerhigh': 30, 'input': None, 'else': 42, ... 

You can use any string as a dictionary key without worrying about shadowing built-ins.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.