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

Python - Output

What am I Learning today?

I am learning how to use output to create create a 'Hello World' program in Python
I am learning how to use output to create different layouts of text
I am learning 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 - Python as a calculator Click to see more

    In Python, you can combine text and numbers in a print statement using speech marks to denote text strings and commas to separate them from numbers. This method allows you to create clear and informative messages. For example, if you're calculating the sum of 5 and 3, your print statement could be

    print("The sum of 5 and 3 is", 5 + 3).

    This technique is fundamental for generating outputs that include both textual explanations and calculated results, preparing you effectively for tasks involving arithmetic operations and output formatting in Python.

    Exercise: Understanding Arithmetic Operations

    Practice using Python to perform basic arithmetic operations and explain the results.

    Example Question

    If I have 5 oranges and my friend gives me 4 more, then how many oranges do i have in total.

    Example of how to answer:

    print("If I have 5 oranges and my friend gives me 4 more, then I have", 5 + 4, "oranges in total.")

    Use the above format to answer each question in your Python script.

    Here are your tasks:

    1. Addition Question: "If you have 35 apples and your friend gives you 26 more, how many apples do you have in total?"
    2. Subtraction Question: "You have 23 cookies, and you give 7 to your friend. How many cookies are left with you?"
    3. Multiplication Question: "If one pack of gum contains 7 pieces and you buy 21 packs, how many pieces of gum do you have?"
    4. Division Question: "You have 155 sweets and you want to share them equally among 5 friends. How many sweets does each friend get?"

    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 - 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 6 - Long text Click to see more

    Sometimes when we print something to the screen we want to print out more than one line at a time. In python we can do that by changing our single speachmarks" to Triple speach marks""" """

    print ("""This is a very very very
    very very very very very very
    very very very long line of text"""
    )
    1. Copy the code above and then run it to see what it does.


    Lesson Challenge

    • E

      Extension Challenge
      Complete one or all of the extension challenges below

    Click here for some ASCII art examples



  • When you are finished don't forget to save your code to 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 - 2025 LearnITwithMrC