Can anyone help me understand Python functions?
1 23 Feb 2018 21:58 by u/carlip
I'm having trouble with an assignment in an Intro to Programming class for Python.
I cannot grasp the concept of how I am supposed to shuffle around variables, into and out of functions. I keep getting "positional errors", then when I think I fixed it, my program doesn't work correctly, but at least no errors.
8 comments
0 u/J_Darnley 23 Feb 2018 22:02
I'm not familiar with Python nor that specific Python error so perhaps you should post some example. I don't understand what you mean by shuffling either. Are you new to programming in general?
0 u/carlip [OP] 23 Feb 2018 22:05
i've never gotten too indepth into any particular language.
What i mean is that i have some variables that i have to do 2 things with, the requirement is that i use 2 separate functions and returns, but i am having trouble splitting the data then reassembling it correctly.
0 u/J_Darnley 23 Feb 2018 22:16
I might have to be creative here and not use python language but...
I would expect 100 and 103 to be printed. Now your case won't be nearly as simple as that.
ais still 99,bis still 101 andargis local to each function. When you say splitting does that mean your data in a string somewhere and you need to get it out?0 u/carlip [OP] 23 Feb 2018 22:19
I have to get 5 inputs as "test scores", then assign a letter grade A-F as well as print the average score and letter grade. All of this has to be formatted into a chart, which i already have worked that out, i just dont get the back end stuff.
0 u/J_Darnley 23 Feb 2018 22:32
I think I see. You either need to store the individual scores in some structure--Python has a great many types but I think the basic one for this is just called a List--or just keep track of a sum and and a count from there an average (the mean) is simple.
0 u/AndrewBlazeIt 24 Feb 2018 00:45
What kind of chart?
Formatted command-line outputs, or some kind of text or graphic file?
0 u/carlip [OP] 24 Feb 2018 01:14
OUTPUT
apparently i was passing the variables to the wrong places, all fucking day...
0 u/MHole 23 Feb 2018 22:36
Read about "variable scope".
You can use the same variable names in different functions and objects, and most of the time they are not shared across those functions or objects.
In other words, a variable may not be available to a function the way you'd expect unless you learn the ins and outs.