In this ICS3U Grade 11 Computer Science lesson you will be learning how to:
Words or sentences in python are called Strings
The command to display things to the screen is the print command
print()
The statement you want to print goes inside the print command brackets and is surrounded by either
Normally I stick to using double quotes because in other programming languages such as Java and C/C#/C++ that is the convention and single quotes are used for single characters in those languages.
Type the following code into the Python Editor.
print("Hello World")
Type the following code into the Python Editor.
print("Hello")
print("World")
Notice that each print statement will print the message on a new line
If you want for some reason to use use multiple print statements but have them display on the same line you can use the end=”” command. You can put any character you want in the double quotes and that will appear at the end of the print statement and not move the cursor to the next line.
Type the following code into the Python Editor.
print("Hello",end="")
print("World")
You will notice there is no space between the words. If you wanted one, you could add it in manually inside your double quotes
A common error you might make is to forget a double quote (You always need a pair) or to forget a bracket (You always need a pair)
Type the following code into the Python Editor and see what happens when you try to run it.
print("Hello"
Type the following code into the Python Editor and see what happens when you try to run it.
print("Hello)
These typing errors are called syntax errrors
Python will tell you what error it encountered, but its not always easy to figure out what you did wrong. Each IDE will also give you a different wording for the error.
Helpful Hint: When python identifies an error on a line, you might want to look at the line above where the error was identified
Certain characters or print options need a special way to print. These are called escape characters
Type the following code into the Python Editor.
print("\tBook Title\n\"Harry Potter\"")
The print statement prints whatever is inside its pair of double quotes.
Watch a video of your teacher summarizing the learning content for this section
Try to code the following questions using an IDE of your choice (Spyder, IDLE, Pycharm, etc). You will save those files on your computer for future reference.
Each question has:
Try your best to solve the problems yourself without looking at the solutions.
Name Your File: “ICS3Uinformation.py”
Write the code that displays the following
Make use of 3 escape characters when you do this and the the “end=” statement
print("\n\n\t\tPaul Rogers")
print("Hamilton Wentworth District School Board\n\tGlendale Secondary School")
print("\nMy Favorite Movie Series are:\n\t\"Harry Potter\" & \"Star Wars\"")
print("\nI only ever wear blue shirts",end = " or ")
print("black shirts\n")
print("I have been teaching computer science since 2004")
Name Your File: “ICS3Ushape.py”
Draw a picture of a cool shape using escape characters in your solution. Something like the picture shown.
print("I think it looks like a face\n")
print("\t \"- -\"")
print("\t o o")
print("\t[- o -]")
print("\t \\_/")
print("\t -")