Posts: 17
Threads: 4
Joined: Sep 2020
Sep-23-2020, 11:18 PM
(This post was last modified: Sep-24-2020, 06:49 AM by buran.)
Create a variable called my_sum that has a value of 10 + 31. However, instead of adding the numbers directly in my_sum, set my_sum to be the result of your adds_numbers function.
def my_sum(adds_numbers):
my_sum = x + y
return my_sum
adds_numbers= 10+31
print(adds_numbers) but something is missing in this so could someone give me an idea about it.
Posts: 1,343
Threads: 2
Joined: May 2019
You have things backwards. Create a VARIABLE named mysum. You created a function. It should use the FUNCTION adds_numbers(). You have a variable named adds_numbers.
Posts: 17
Threads: 4
Joined: Sep 2020
Sep-23-2020, 11:59 PM
(This post was last modified: Sep-24-2020, 06:50 AM by buran.)
(Sep-23-2020, 11:35 PM)jefsummers Wrote: You have things backwards. Create a VARIABLE named mysum. You created a function. It should use the FUNCTION adds_numbers(). You have a variable named adds_numbers.
Hi Thanks for your prompt reply but my doubt is if we declare variable outside the function how do we call it here? could you give me some idea on the same?
my_sum= 10 + 31
def adds_numbers():
my_sum = (adds_numbers(x+y))
return my_sum
adds_numbers= 10+31
print(adds_numbers) even this is not pass through.
Posts: 17
Threads: 4
Joined: Sep 2020
Sep-24-2020, 06:29 AM
(This post was last modified: Sep-24-2020, 06:50 AM by buran.)
I tried as below and it has small issue it seems.
def adds_numbers(x, y):
my_sum = x + y
return my_sum
my_sum = adds_numbers(10, 31)
print(my_sum)
Posts: 8,085
Threads: 153
Joined: Sep 2016
line#4 must be outside the function
def adds_numbers(x, y):
my_sum = x + y
return my_sum
my_sum = adds_numbers(10, 31)
print(my_sum)
Posts: 17
Threads: 4
Joined: Sep 2020
Sep-24-2020, 12:25 PM
(This post was last modified: Sep-24-2020, 12:26 PM by prasanthbab1234.)
(Sep-24-2020, 06:29 AM)prasanthbab1234 Wrote: I tried as below and it has small issue it seems.
def adds_numbers(x, y):
my_sum = x + y
return my_sum
my_sum = adds_numbers(10, 31)
print(my_sum)
Hi Buran,
I'm new to this forum so excuse me if there's any issue in my post as I copy paste the code from code editor and not sure it won't copied here properly and I tried with given format and I got following error
message saying my_sum not hardcoded so please explain how to hard code?
def adds_numbers(x, y):
my_sum = x + y
return my_sum
my_sum = adds_numbers(10, 31)
print(my_sum) [/quote]
Posts: 178
Threads: 69
Joined: Oct 2018
Try this:_
def adds_numbers(x, y):
my_sum = x + y
return my_sum
my_sum = adds_numbers(10, 31)
print(my_sum)
Posts: 8,085
Threads: 153
Joined: Sep 2016
(Sep-24-2020, 12:25 PM)prasanthbab1234 Wrote: I got following error
message saying my_sum not hardcoded It would say that my_sum is not defined, not harcoded.
All use of my_sum on lines 2-4 is inside the function i.e. it's a variable inside the scope of the functio
my_sum on line 5 is in global scope, i.e. that is different variable than the ones inside the function.
If you move line 4 outside the function as I show you, it's a different matter. In my code on line 4 result returned from the function is assigned to my_sum and then on line 5 you can print it (it's defined)
Posts: 17
Threads: 4
Joined: Sep 2020
(Sep-24-2020, 12:25 PM)ebolisa Wrote: Try this:_
def adds_numbers(x, y):
my_sum = x + y
return my_sum
my_sum = adds_numbers(10, 31)
print(my_sum)
I tried with both options and issue remains same as we need to hard code my_sum but not sure how?
Posts: 8,085
Threads: 153
Joined: Sep 2016
(Sep-24-2020, 12:44 PM)prasanthbab1234 Wrote: as we need to hard code my_sum but not sure how? It's unclear what you want. Is this homework? Post the text of the assignment verbatim.
Your initial request was clear:
(Sep-23-2020, 11:18 PM)prasanthbab1234 Wrote: instead of adding the numbers directly in my_sum, set my_sum to be the result of your adds_numbers function.
|