Functions, Practice Makes Perfect


#1

https://www.codecademy.com/courses/learn-python/lessons/functions/exercises/practice-makes-perfect

When I try to run my code:

def cube(number):
  return number**3

def by_three(number):
  if n % 3 == 0:
  	return cube(number)
  
  else:
  		return False

It gives me the following message: by_three(1) resulted in an error: global name ‘n’ is not defined
What does this mean and how can I fix it?
Thank you.


#2

Look at your undefined variable n. n was not defined. If we want to check if our number is fully divisible by 3, then we should use our parameter number to do this, so when we call our function, our argument will pass into the parameter and be checked there (in number). :slight_smile: Do you know what I mean?


#3

Thanks! Managed to make it work


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.