I am a retiree who will be working with some 8th grade kids with Raspberry Pi's. I am a Mac user and my only programming experience is with BASIC and Fortran. Right now I am trying to learn Python and get the project "Sense Hat Marble Maze" on the raspberry.org/learing site to work, and there are somethings I don't understand.
1. What does the instruction 'sense = SenseHat()' do? My guess is that 'sense' is a variable and 'SenseHat()' is a function. What is it that the function is storing in 'sense'?
2. This is the code for a subroutine in that project .
def move_marble(pitch,roll,x,y):
new_x = x
new_y = y
if 1 < pitch < 179:
new_x -= 1
elif 359 > pitch > 181:
new_x += 1
return new_x, new_y
The first line passes values for 'pitch' and 'roll' that are read from the Sense Hat and values for the variables x and y. However I am puzzled by the 'return new_x, new_y'. How does the program know that those are new values for the x and y variables that were passed in. Does that statement just put the new values in x and y because they were the only variables passed in?
3. Another subroutine is:
def check_wall(x,y,new_x,new_y):
if maze[new_y][new_x] != r:
return new_x, new_y
elif maze[new_y][x] != r:
return x, new_y
elif maze[y][new_x] != r:
return new_x, y
return x,y
The instruction 'if maze[new_y][new_x] != r:' seems strange to me in that the y-coordinate is listed before the x-coordinate. All of the other instructions list the x-coordingate first. At first I thought that was a typo.
