## ~ Python Programming: An absolute beginners introduction

### Complete beginner? Welcome!

What is Python, Who created it, What is it used for?

### Who this introductory series is for?

Teachers can use this 'absolute beginner' series to introduce mixed ability and 'starter' groups to python programming. Learners can also independently go through some of the basics before going on to consolidate these basics in the latter series in SOLVE AND LEARN. The series adopts a scaffolded approach with a simple pedagogy for delivering complex skills. Teachers can chose to use the video presentations below OR download the ppts themselves to lead a lesson. Alternatively, why not get a pupil to lead the lesson (after they have watched the video and practiced the skills for each section themselves).Use the tracking worksheet to help pupils track their progress

Run the code below, play around with it, and see if you can answer the following questions.

Q1. In your own words, explain what the two print commands are doing?

Q2. x and y are both variables that have been given values. Cut and paste the line in which they are being added together.

Q3. What is the value contained in variable z?

Note: You can print the page, screenshot, or write down the answers in your notebook

### Code Snippet

```#Your first ever program
def main():
print("Hello there, this is your computer speaking")
x=3
y=2
z=x+y
print(z)

main()
```

Run the code below, play around with it, and see if you can answer the following questions.

Q1. If you change the variable "move_speed" to 100, what will happen?

Q2. There are four functions (defs) that control movement. Name them.

Q3. The parts of the code that start with a hash tag (#) are called.....?

Note: You can print the page, screenshot, or write down the answers in your notebook

### Code

```# Click in the righthand window to make it active then use your arrow
# keys to control the spaceship!
import turtle

screen = turtle.Screen()

# this assures that the size of the screen will always be 400x400 ...
screen.setup(400, 400)

# ... which is the same size as our image
# now set the background to our space image
screen.bgpic("space.jpg")

# Or, set the shape of a turtle
turtle.shape("rocketship.png")

move_speed = 5
turn_speed = 5

# these defs control the movement of our "turtle"
def forward():
turtle.forward(move_speed)

def backward():
turtle.backward(move_speed)

def left():
turtle.left(turn_speed)

def right():
turtle.right(turn_speed)

turtle.penup()
turtle.speed(0)
turtle.home()

# now associate the defs from above with certain keyboard events
screen.onkey(forward, "Up")
screen.onkey(backward, "Down")
screen.onkey(left, "Left")
screen.onkey(right, "Right")
screen.listen()
```

Run the code below, play around with it, and see if you can answer the following questions.

Q1. How many functions are there in this program?

Q2. What would you have to write in the questions function, to get the program to jump to the lastfunction?

Q3. What do you notice must be included after each function declaration. For example, after def main()? (hint: c _ _ _ _ )

Note: You can print the page, screenshot, or write down the answers in your notebook

### Code

```def main():
print("This is the main function")
quiz()

def quiz():
print("This is the quiz function")
questions()

def questions():
print("This is the questions function")

def lastfunction():
print("This is the last function")
print("whoo hoo")

main()
```

Run the code below, play around with it, and see if you can answer the following questions.

Q1. Indentation matters in Python. Everything inside any function is indented as well as inside an if function. How many spaces appear to be used?

Q2. Syntax also matters in Python. Change one of the 'print' commands to 'PRINT'(Capitals). Will it work? Yes or No?

Q3. If you play the program, you will notice that even after it says 'goodbye' it returns to the main menu. How can you stop this from happening?

Note: You can print the page, screenshot, or write down the answers in your notebook

### Code

```def main():
print("Press P to Play the game")
print("Press Q to Quit the game")

choice=input("Enter Choice:")
if choice=="p" or choice=="P":
play()
elif choice=="Q" or choice=="q":
quit()

def play():
print("========================")
main()

def quit():
print("Leaving us so soon?")
print("===Goodbye=====")
main()

main()
```

Run the code below, play around with it, and you will note that there are THREE ERRORS that stop it from working properly.

Q1. The first error is on line 7, can you see what it is? Fix this if you can!

Q2. The second error is on line 12. Can you see what it is and fix this so that the program jumps to the goodbye function?

Q3. The third error is in the goodbye function on line 15. Can you fix the syntax error to get the program to print the "Goodbyyyyeeee" message?

Note: You can print the page, screenshot, or write down the answers in your notebook

### Code

```import time

def main():
print("Hello, this is your computer speaking")
x=7
time.sleep(0.9)
print("My favourite number is",y)
time.sleep(0.9)
print("Well....it has been nice chatting, goodbye for now!")
print("....actually, one more thing:")
goodbye

def goodbye():
Print("************GOOOOODBYEEEEEEEEEEEEEEEEEEE!!!!!!!!!!!!****************************")

main()
```

### Final Challenge

Use your knowledge and skills from the completed tasks. Answer as many of the following questions as you can. Feel free to use the internet for your answers.

Note: You can print the page, screenshot, or write down the answers in your notebook

### Code

```def main():
name="Jonathan"
age=33
x=6
z=2.0
print(name)
print(age)
print(x)
print(z)
print(x+z)
print(y)
main()
```