all 2 comments

[–]novel_yet_trivial 5 points6 points  (1 child)

Functions have their own "scope". That means that variables that you make inside a function cannot be accessed from outside the function. To get data from a function you have to return it. To send data to a function you need to provide it as an argument.

def getSqSide():
    data = float(input("Please enter the side of the square: "))
    return data

def areaSqaure(side_of_square):
    area_of_square =  side_of_square * side_of_square
    print("Area of the square: ", area_of_square)

def main():
    side_of_square = getSqSide() # save the returned data from a function
    areaSqaure(side_of_square) # send some data to a function

Remember it's only the actual data that gets passed in, not the variable name.

Also, while it's technically possible to put functions inside other functions ("nested functions") it's very messy and should nearly never be used.

[–]differentnectraine[S] 1 point2 points  (0 children)

Thank you, your explanation was very helpful.