I recently started learning Python and have some code here.
...
workout = input("Work out if you won?")
if workout == "y":
ballone()
elif workout == "n":
print("Okay.")
sys.exit("Not working out if you won")
else:
sys.exit("Could not understand")
##Ball one
def ballone():
...
The issue is calling 'ballone'. You can see that it is defined and works perfectly when called from the command line (ballone())
Any ideas? I have scoured the net but cannot seem to find anything to help me. If any more code needs posting then please let me know :)
Move the function definition to before the lines that use it.
def ballone():
# ...
if workout == "y":
ballone()
elif workout == "n":
print("Okay.")
sys.exit("Not working out if you won")
else:
sys.exit("Could not understand")
Functions are stored in identifiers (variables), just like your workout
value. If you don't define it first, how is Python to know it'll be defined later?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With