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

Data Output

What do I need to Learn?

I need to learn how to use python to output data to the screen in different formats
I need to learn how to debug code in python and fix simple errors

Knowledge Organiser

×

Lesson

Task 1 - Getting Organised Click to see more

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

  • To download the PowerPoint by clicking on the image below


  • Save your PowerPoint as 'Programming 1'


  • Task 2 - 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 PYTHON into your search bar.
    2. Now select IDLE.
    3. From the shell menu Select 'File' > 'New File'.
    4. Type in the code print ("Hello World")
    5. Now select Run > Run Module (it will prompt you to save your file first - call your file name 'hello world')



    Task 3 - 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” )

    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 code using #comments



  • When you are finished screenshot your commented code into your powerpoint

  • Task 4 - 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 code using #comments



  • When you are finished screenshot your updated commented code into your powerpoint

  • Task 5 - Adding numbers Click to see more

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

    print ("8+3")
    print(8+3)
    print ("8" + "3")
    1. What is the difference in the output for each of the statements?

    Explain your answers in your code using #comments



  • When you are finished screenshot your updated commented code into 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.



  • When you are finished screenshot your corrected code into your powerpoint

  • My Notes: Text_Programming

    Student_Comment_2 not found

    Task Notes/Comments - Add here Click to see more

    Comments/Notes

    Copyright © 2013 -2019 LearnITwithMrC