~ Programming in Python - Part 1 -


Welcome

Programming in Python is something you are going to love! Our very first lesson is going to tell you why learning Python is going to be an amazing experience! It is one of the fastest growing languages in terms of popularity, power and usage and the likes of youtube, and google use it in their applications. 

What to do

Go through each lesson online and follow the slides closely. Your teacher has access to the full teacher /teaching powerpoint with solutions. version that they will go through with you in class ahead of your completing the challenges. Download the student powerpoint, and complete it for submission. . Lesson 1 - 4 will take you through all the basics in Python including variables, selection, iteration and much much more!

Python 3

Download it here: https://www.python.org/downloads/

Please note, in this series we will be working with Python 3 - so make sure you have the right version. Head over to www.teachyourselfpython.com for more lessons all the way up to game design and more advanced concepts!

A little history ...

Python is an increasingly popular and widely used high-level, general-purpose, interpreted, dynamic programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than possible in languages such as C++ or Java. The language provides constructs intended to enable writing clear programs on both a small and large scale

We'd highly recommend you head over to www.teachyourselfpython.com - your one stop site for all things Python.

History

Python was conceived in the late 1980s, and its implementation began in December 1989 by Guido van Rossum (see above image) at Centrum Wiskunde & Informatica (CWI) in the Netherlands as a successor to the ABC language(itself inspired by SETL)capable of exception handling and interfacing with the operating system Amoeba. Van Rossum is Python's principal author, and his continuing central role in deciding the direction of Python is reflected in the title given to him by the Python community, benevolent dictator for life(BDFL).

About the origin of Python, Van Rossum wrote in 1996:

Over six years ago, in December 1989, I was looking for a "hobby" programming project that would keep me occupied during the week around Christmas. My office ... would be closed, but I had a home computer, and not much else on my hands. I decided to write an interpreter for the new scripting language I had been thinking about lately: a descendant of ABC that would appeal to Unix/C hackers. I chose Python as a working title for the project, being in a slightly irreverent mood (and a big fan of Monty Python's Flying Circus).

Creative Commons: https://en.wikipedia.org  Oa 80x15 orange.png

Go through the powerpoint slides online and then when you're ready to start coding, download the student tasks/challenges powerpoint below

Download Student Power Point

Go through the powerpoint slides online and then when you're ready to start coding, download the student tasks/challenges powerpoint below

Download Student Power Point

Go through the powerpoint slides online and then when you're ready to start coding, download the student tasks/challenges powerpoint below

Download Student Power Point

Go through the powerpoint slides online and then when you're ready to start coding, download the student tasks/challenges powerpoint below

Download Student Power Point

Additional Challenges

Variables, and Conditional Logic (IF, ELSE etc)

Challenge 1 - Conditional Logic Recap

Copy and paste the following code and complete the questions as commented

#IF Statements

import time     #This import will allow you to pause the program

#Example of a basic IF Statement
#Tests if the number entered is even or odd
def E1():
    x = int(input("Enter a whole number: "))        #Need to convert input to integer using int() function
    if x % 2 == 0:                                  #Check if the condition is true (note the double ==)
        print("The number entered is an even number")   #This code executes if it is true (notice the indent)
    else:                                           #The code will jump to here if the condition is false
        print("The number entered is an odd number")    #This code executes if it is false (notice the indent)
    print("Thank you for using this program")       #This code will execute if it is true OR false (not indented)

#Example of a nested IF statement
#Takes two numbers and tests if one if bigger than the other
def E2():
    print("Please enter two numbers.")
    x = int(input("Number 1: "))
    y = int(input("Number 2: "))

    if x < y :
        print("Number 1 is less than number 2")
    else:
        if x > y:                                   #This if statement will only execute if the first one is false
            print("Number 1 is greater than number 2")
        else:
            print("Number 1 and number 2 are equal")

    print("Thank you for using this program")       #This code will always execute (not indented into if statement)

#Example of IF statement with two tests (elif)
#Checks to see if the user inputs a number within the given range
def E3():
    print("This program will check if you enter a number in the given range.")
    userNumber = int(input("Please enter a number from 4 to 7: "))

    if userNumber > 7:                          #This check will happen first
        print("\n Number entered is too high")     #If it is true, it will print this and exit the IF statement
    elif userNumber < 4:                        #This check will only happen if the first one is false
        print("\n Number entered is too low")
    else:
        print("\n Number is within range")

    print("Thank you for using this program")

#Example of IF statement that combines two tests
#It is possible to use AND, OR and NOT
#This program is used to test a students exam score and attendance
def E4():
    print("Please enter your score and attendance")
    score = int(input("Test Score (%): "))
    attendance = int(input("Attendance (%): "))

    if score >= 70 and attendance >= 80:        #Both of these conditions must be true...
        print("Excellent, well done")           #...for this to be executed
    elif score >= 70 and attendance < 80:
        print("Excellent test score, but you need to attend more lessons")
    elif score < 70 and attendance >=80:
        print("Your attendance is good, but you need to study harder")
    else:
        print("You need to study harder and attend more lessons")

#def Q1():
    #Write a program that asks for the users age and tells them if they are old enough to vote or not

#def Q2():
    #Write a program that asks for two football team names, and then the score for each team
    #You program should then say if the teams get 3 points, 1 point or 0 points for the result


def Q3():
    #Choose your own adventure game
    #Some examples can be found here:
    #http://editthis.info/create_your_own_adventure/
    #http://chooseyourstory.com/
    #Using if statements, write an adventure game.  A basic start is shown below - change it completely or continue this story

    print("You are stood outside. The rain pours down as you look into the darkness of the cave.  You swear you can see eyes looking back at you, but maybe it is just the reflection of the moon light.")
    time.sleep(4)               #This is used to pause the code and add suspense.  Note: You must "import time" at the start of your program
    print("\na = Enter the cave.\nb = Go home now")
    answer = input("Enter your choice: ")
    answer = answer.lower()     #Make sure the answer is lower case before testing it
    if answer == "a":           #Don't forget you need two =
        print("You enter the cave...")
        time.sleep(2)
        print("Your foot touches something...")
        time.sleep(2)
        answer = input("It is a lantern!  Do you wish to light it? (y/n)")
        answer = answer.lower()
        if answer == "y":
            print("The lantern lights easily...")
            time.sleep(2)
            print("The light flickers in the darkness and stood in the distance you can make out the shape of...")
            time.sleep(4)
            print("You can continue the story from here!")
        elif answer == "n":
            print("You feel the breath of something close to your face...")
            time.sleep(2)
            print("Nobody hears your screams.  You will never see another morning.")
            time.sleep(2)
            print("GAME OVER!")
        else:
            print("You didn't enter a correct option.  Your mistake is costly!")
            time.sleep(2)
            print("GAME OVER!")
    elif answer == "b":
        print("You might not be an adventurer, but at least you are alive and home safe.")
        time.sleep(2)
        print("GAME OVER!")
    else:
        print("You didn't enter a correct option.  Your mistake is costly!")
        time.sleep(2)
        print("GAME OVER!")

    print("Thank you for playing.")

Challenge 2 - Variables Recap

#Variables

def E1():
    myName = "Moose"     #This places a string "Moose" into a variable named myName
    print(myName)       #This outputs the value of myName to the screen
    myName = "John"     #This replaces "Moose" with the name "John"
    print(myName)

def E2():
    x = 3               #This puts the number 3 into a variable named x
    print(x)            #This shows the value of x to the user
    input()             #This causes the program to pause until the user presses Enter
    x = 3 + 1           #We replace the value of x with the sum of 3 + 1 - the number 4
    print(x)
    input()
    x = x + 6           #We replace x with the sum of x + 6 (4 + 6) - the number 10
    print(x)

#def Q1():              #Delete the # before the def when you want to work on the question
    #Write a joke program.  It should tell the joke and wait for the user to press
    #enter before telling the punch line
  
#def Q2():
    #Ask the user to input 3 different integers
    #Multiply the first two together
    #Divide the result by the third number
    #Print the end result to the screen
    
#def Q3():
    #Ask for an amount of money to be entered
    #Break the money down into £50, £20, £10 and £5 and show any remaining amounts
    

End of topic assessment

1. Please submit all your lesson powerpoints with solutions/screenshots as appropriate.

2. Complete the challenges in additional challenges and submit your solutions.