John OConnor
John OConnor

Reputation: 23

sending variables between functions

Probably a duplicate but after 15 min I couldn't find an answer to my question, probably my poor coding terminology.

what is it about my logic that I'm incorrectly passing my arguments? Please refrain from chastising my choice code itself, I'm not very good at this and I know it.

The program is supposed to:

Items (a) and (b) should be produced by the function that creates the sets; there should be a separate function for each of the others. btw is case it somehow helps file 1 is:

file 2 is:

Upvotes: 0

Views: 35

Answers (1)

lvc
lvc

Reputation: 35069

Variables that you use inside your file1 and file2 functions are invisible to other functions, so that they can use the same names for slightly different purposes without interfering with each other. This means that your main function can't see set_1 and set_2 from those functions. The good news is that you've already happened on the way to hand those objects back to the calling function: by use of return. You're using it exactly right in those two functions, you just need to link it up in main - the function call there evaluates to the value the function returns, so to get it to work you just need to do this:

set_1 = file1()
set_2 = file2()

You can call these two variables whatever you want - they don't need to match the name of the variable you return inside the function.

Upvotes: 2

Related Questions