Sublime Forum

Function/parameter question

#1

Hey guys so I’m learning about functions and parameters and ive been finding it hard i watched a YouTube video on it and followed this guys code buy when i build it i get errors, anyone can help?
Thanks

def simple_addition(num1, num2):
answer = num1 + num2
print(“num1 is” + num1)
print(answer)
simple_addition(5, 3)

0 Likes

#2

The hint to your issue is in the error message you’re getting:

    print("num1 is" + num1)
TypeError: can only concatenate str (not "int") to str

The + operator adds numbers or joins strings, but here you’re asking it to join a string with a number, which is not valid.

You want to replace the + in the print statement with a ,:

def simple_addition(num1, num2):
    answer = num1 + num2
    print("num1 is" , num1)
    print(answer)

simple_addition(5, 3)
0 Likes

#3

You sir are a godsend to budding programmers, thankyouuuu!

0 Likes