The Traceback is telling you where your error is, and what is wrong:
Traceback (most recent call last):
File “script.py”, line 21, in
HeadsTails(Tail, 11) <<< this line is the problematic one
NameError: name ‘Tail’ is not defined <<< and this line is explaining the problem
When Python says
name 'Tail' is not defined, it is saying “I don’t know what that variable is”. This is because you don’t have a global variable in that code snippet called
You’ve defined that variable inside your function
HeadsTails, which makes it locally-scoped variable. It exists only within that function, and is only accessible to other code within that function. You can’t access it from outside.
Additionally, there are some other mistakes you’ve made with the program. For example, your
HeadsTails function accepts a parameter
guess… but almost immediately you’re re-assigning this, inside the function, by asking the user to
input a new guess.
Same thing with
bet - it’s a parameter in your function, but again you’re re-assigning it inside of the function by taking user input.
Hopefully that’ll help you solve the immediate error, and improve the overall structure of your coin flipping program.