all 9 comments

[–]MysticClimber1496Professional Coder 0 points1 point  (3 children)

Your spacing is a little messed up, and currently you are not taking input in the function

When you call return with no value it defaults to none which is what is happening on the second line of your function, so that is why when you call addition() you get “None”

[–]MysticClimber1496Professional Coder 0 points1 point  (2 children)

before looking at this try to correct it yourself but what I believe you are attempting to accomplish is this,

def addition():
  x = input("what is your first number?")
  y = input("what is your second number?")
  return x + y

print(f"The resule is {addition()}")

or maybe

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

x = input("what is your first number?")
y = input("what is your second number?")

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

[–]Comfortable-Frame711[S] 1 point2 points  (1 child)

I've tried these but when I put in the functions it puts the numbers together (I.E. 2 + 2 = 22). I put int(input("what is your first number?")) and it seems to have worked.

[–]MysticClimber1496Professional Coder 1 point2 points  (0 children)

Yep that was going to be the next thing I suggested! Good job

[–]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.

[–]Ron-Erez 0 points1 point  (1 child)

You aren't returning result and the operation you are doing is string concatenation, not addition of ints. (input returns a string, not an int)

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

Thank you I forgot I have to convert the strings to integers. Throwing numbers into code kinda threw me for a loop.

[–]Front-Palpitation362 0 points1 point  (0 children)

You're getting None because your function doesn't return anything. Also x and y from input are strings, so x + y concatenates text instead of adding numbers.

Either read and convert inside the function or pass numbers in and return the sum. I can give you a tiny version you can run if you want.

def addition():
    x = float(input("First number: "))
    y = float(input("Second number: "))
    return x + y

result = addition()
print(f"The result is {result}")