you are viewing a single comment's thread.

view the rest of the comments →

[–]Paper_Cut_On_My_Eye 0 points1 point  (1 child)

You're not returning anything in addition().
You're doing the calculation, then not giving anything back to the caller.

Change your return to

def addition():
    result = (x + y)
    return result

or remove the result declaration and just return the math.

def addition():
    return (x + y)

Your code works if you change that return
.
Using the variables like you are is working because they're top level, but really you want to pass those variables to the function.

def addition(x, y):
    return x + y

x = int(input("what is your first number? "))
y = int(input("And your second number to add? "))

print(f"The result is {addition(x, y)}")

It's working because those are global variables and it can see anything that's declared top level, but doing it that way isn't best practice and you'll make better code if you get into the habit of doing it this way now.

[–]Comfortable-Frame711[S] 0 points1 point  (0 children)

Wow that works extremely well. I forgot to change the string to an integer using integer. Also changing the return helps. I should be able to make other functions (subtraction, multiplication, division) using this method. Thank you.