def sumOfStudentDigits():
studentdigit = (studentdigit1 + studentdigit2 + studentdigit3 + studentdigit4 + studentdigit5 + studentdigit6 + studentdigit7)
studentdigit1=3 studentdigit2=6 studentdigit3=9 studentdigit4=3
studentdigit5=1 studentdigit6=0 studentdigit7=0
I need to assign seven digits to seven variables and add them together.
If your confusion is how to get the
studentdigit
s into your function, you can pass them into the function like this:My advice would be to have all those digits stored in a list, and then pass merely that list to the function, then iterate over the list:
We have to set
sum = 0
before we can usesum
because python wants to know whatsum
is before it uses it, so we assign it0
so that we can count up from there. Notice howstudentdigitlist
andlistofdigits
are different? You can pass a list of any name to the function, all that matters is that you use the variable (ie a list in this case) name that you have used indef myfunction(yourvariable):
throughout the function definition. Python with substitute whatever you pass into the function for where you have that placeholder name within the function. Then when you run the function: eg