I am unclear on the behavior of using a function. Below is a short code I wrote to print an amount out after inputting the number of match.

# TEST Function.py

def change(amount):
    if match == 1:
        amount = 0
    if match == 2:
        amount = 0
    if match == 3:
        amount = 3

match = raw_input("How many matches?: ")
change(match)
print amount

ERROR Message:

How many matches?: 2
Traceback (most recent call last):
  File "/home/ken/Python262/TEST Function.py", line 13, in <module>
    print amount
NameError: name 'amount' is not defined

How do I print out the amount of 0 if I input 2?

Should it be def change(match) instead of def change(amount)?

Perhaps, change(amount) instead of change(match)?

Perhaps, I need to add return somewhere?

Thanking you all in advance for your assistance.

Ken
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to