Computer Science LearnITWithMrC ⛯ Year 7 Year 8 Year 9 GCSE
Responsive image

Python - Output

What do I need to Learn?

I need to learn how to use output to create create a 'Hello World' program in Python
I need to learn how to use output to create different layouts of text
I need to learn how to identify and correct common errors in Python programs

Knowledge Organiser

×

Lesson

Task 1 - Getting Organised - PowerPoint Click to see more

  1. Set your Learning Objectives to red.

  2. We are going to save all of our work for this topic into a PowerPoint like we did in our assessment.

  3. To download the PowerPoint by clicking on the image below


  4. Save your PowerPoint as 'Programming 1'


Task 2 - Getting Organised - Python Click to see more

Choose your Python

  • You have two python options for completing todays lesson.

  • Option 1

    Thonny

    In class we are going to be using the Python tool called 'Thonny' if you are at home you can also download it by clicking on the image below

    Option 2

    CodeSkulptor3

    If for any reason you cannot download Thonny then click on the link below to use an online version of Python called CodeSkulptor3. Just be aware that the lessons are based upon using python in Thonny however the code will be exactly the same.


    Task 3 - Introducing Output Click to see more

    In python we use built in functions to help us with our input and output. The function we use to output to the screen is print() and the function we use to get input from the keyboard is input().

    Let us look at the the output method print() first.



    1. Type in Thonny into your search bar.
    2. From the menu Select 'File' > 'New File'.
    3. You should now see your 'IDE' (Integrated Development Environment looking like the one below, with your file named 'untitled'

    We are now ready to create our first program


    1. Type in the following code:
    2. print ("Hello World")
    3. To make our code work we have to Run it.
    4. Select Run by clicking on the green button with the triangle in it. (it will now pop up the 'Save as window'save your file name as 'hello world').


  • After you have Saved and Run your code you should see the words "Hello World" appear at the bottom in what is called your Shell window

  • Task 4 - Printing styles Click to see more

    Add the following lines of code to your 'hello world' program

    print(“Hello” )
    print(“World” )

    print(“Hello \n World” )
    print(“Hello”,“World” )
    print(“Hello” + “World” )

    Try and answer the questions below.


    1. What is the difference in the output for each of the statements?
    2. What does the “\n” do ?
    3. What is the difference between the “,” and the “+”?

    Explain your answers in your Powerpoint next to a screenshot of your code



  • When you are finished don't forget to save your your powerpoint

  • Task 5 - Long text Click to see more

    Add the following lines of code to your 'hello world' program

    print ("This is a very very very\
    very very very very very very\
    very very very long line"
    )
    print ("This is a very very very\n\
    very very very very very very\n\
    very very very long line"
    )
    print ("""This is a very very very
    very very very very very very
    very very very long line"""
    )
    1. What is the difference in the output for each of the statements?
    2. What does the “\” do ?
    3. What does the """ do?

    Explain your answers in your Powerpoint next to a screenshot of your code



  • When you are finished don't forget to save your your powerpoint

  • Task 6 - Finding Errors(Debugging) Click to see more

    Sometimes when your program does not work it is often the case that you have made a syntax error. Syntax errors are typographical mistakes that the programmer has made. When the code get translated for the computer to understand you will get an error message. Sometimes the message is useful, sometimes it is not!

    When you are writing programs especially as they get more complex it is very difficult to not to make syntax errors (i do it all the time), so it is good to be able to understand the error messages so you can fix it yourself. As you get more experienced you will learn to interpret the error messages more easily and quickly.

    Common Errors

      Forgotten bracket: - You get the message “invalid syntax” in a pop up box along with the line after the line with the error being highlighted in red.
      Forgotten speech mark: - You get the message “EOL while scanning string literal” in a pop up box along with the line of the error being highlighted in red.
      Name Error: - You get the message “Name error” when you mispell a function namelike I have done with print as you can see in the message below.


    Copy the code below into a new python file and save it as "debugging"

    Try and fix all the errors so that the code works

    print("Hello Everyone)
    print("This is a poem")
    
    print(Once there was a little boy,)
    print(With curly hair and pleasant eye—")
    Print("A boy who always told the truth,")
    print(And never, never told a lie.")
    
    Print("And when he trotted off to school,")
    pint("The children all about would cry,")
    PRINT("There goes the curly-headed boy—")
    print(The "boy that never tells a lie.")
    


    Add #comments at the end of each line where there is an error, stating what type of error it was.


    Explain your answers in your Powerpoint next to a screenshot of your code



  • When you are finished don't forget to save your your powerpoint

  • Task 7 - Lesson review Click to see more

    Summing it all up

    Lets look at the learning outcomes and decide which one best describes our current level of understanding :

    Tick the one you feel is closest to your level

    Learning Outcomes I need to learn how to use output to create create a 'Hello World' program in Python

    • I have a basic understanding of how I can use output to create create a 'Hello World' program in Python with a little help from my teacher
    • I can show my teacher that I can use output to create create a 'Hello World' program in Python without their help.
    • I can use output to create create a 'Hello World' program in Python independently and I can also explain it to others and can complete any extension tasks I am given.

    🠜 Now update your learning objectivesClick on the Assessment image

    My Notes: coding-p

    Student_Comment_4 not found

    Task Notes/Comments - Add here Click to see more

    Comments/Notes

    Copyright © 2013 -2019 LearnITwithMrC