Python - Variables and Data types
Set your Learning Objectives to red.
We are going to save all of our work for this topic into a PowerPoint like we did in our assessment.
Save your PowerPoint as 'Programming 1'
You have two python options for completing todays lesson.
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
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.
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.
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.
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.
Explain your answers in your Powerpoint next to a screenshot of your code
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.
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.
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""")
Click here for some ASCII art examples
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