I tried to execute the following code,
def dating_age (my_age):
if my_age < 18 & my_age >= 13:
girls_age = my_age/2+5
elif my_age <13:
print ("You are ineligible to date")
else:
girls_age = my_age/2+9
return girls_age
my_age_input = int(input("Enter your age: "))
dating_limit = (dating_age(my_age_input))
if my_age_input < 13:
print (dating_limit)
else:
print ("I can date Girls of" , int(dating_limit) , "and higher")
and got the following error:
Enter your age: 12
You are ineligible to date
Traceback (most recent call last):
File "C:/Users/animi/PycharmProjects/LearnPython/Functions.py", line 27, in <module>
dating_limit = (dating_age(my_age_input))
File "C:/Users/animi/PycharmProjects/LearnPython/Functions.py", line 24, in dating_age
return girls_age
UnboundLocalError: local variable 'girls_age' referenced before assignment
Process finished with exit code 1
If i enter anything above 13 as input, there is no error code generated. Why is such an error occurring and how to avoid it?
Also, any tips to improve my programming practice is welcome.