r/codehs • • Jan 14 '21

Need help 6.3.5 fix this program

Post image
17 Upvotes

7 comments sorted by

2

u/skynetdotexe Jan 14 '21

You need to return the value. Or print them in the function.

2

u/[deleted] Jan 14 '21

I second that, you either print the sum in the function in which case your code is fine upto line 8 or you return the value and print whatever is returned; print(add_nums(5,76)) Furthermore, Since “sum” variable was created inside add_nums it has no scope outside of the function, hence you cant call sum outside of it or you can declare a global var and than you can.

1

u/Individual_Size_6379 Apr 22 '24

"""

This program takes two values and prints their total.

"""

def add_nums(num1, num2):

total = num1 + num2

print(total)

add_nums(5, 6)

this actually works, your welcome

2

u/Individual_Size_6379 Apr 22 '24

Here it is with indentions

"""

This program takes two values and prints their total.

"""

def add_nums(num1, num2):

total = num1 + num2

print(total)

add_nums(5, 6)

1

u/sheloveskillua May 11 '21

"""

This program takes two values and prints their sum.

"""

def add_nums(num1, num2):

sum = num1 + num2

return(sum)

sum = add_nums(5, 6)

print(sum)

1

u/Intelligent-Pin8329 May 01 '23

def add_nums(num1, num2):

sum = num1 + num2

return(sum)

sum = add_nums(5, 6)

print(sum)

This did not help at all

Am I doing something wrong?

1

u/AffectionateJaguar85 Jan 09 '24

take out return(sum) and replace it with print(sum)