Introductory Python # the csinsc module
# needed for goto
Reference Sheet label .ask_again
password = input("Enter password:")
Displaying Text on the Screen
if password != "letmein":
print("Hello, world!")
print("Incorrect, try again.")
goto .ask_again
Pausing Until the User Presses [ENTER] to
print("Welcome inside!")
Continue
input("Press [Enter] to continue")
Displaying Text in Colour
from csinsc import * # using code from
Comments
# the csinsc module
# These are comments, everything after # needed for colour
# the hash sign is ignored by Python
print(Colour.red + "In red.")
print(Colour.blue + "In blue.")
Letting the User Enter Text, Displaying it to
print(Highlight.blue + "Blue highlight.")
the Screen
print(Highlight.cyan + "Cyan highlight.")
name = input("Please enter your name:") print(Style.bold + "In bold.")
print(Style.underline + "Underlined.")
print("Hi, " + name + ", how are you?") print(Colour.reset + "Back to normal.")
print(Colour.red + Highlight.blue + Style.bold +
Making a Decision with an if Statement
"Combined red text, blue highlight and bolded!")
if name == "Joan":
print("My name is Joan too!")
print("Have a nice day!") Colour and Style Guide
Colour.red Highlight.red
# Note:"Have a nice day!" is always shown Colour.orange Highlight.orange
# because it is not part of the IF Colour.yellow Highlight.yellow
# code block Colour.green Highlight.green
Colour.cyan Highlight.cyan
Colour.blue Highlight.blue
Not Equals with an if Statement
Colour.purple Highlight.purple
if name != "Tom": Colour.magenta Highlight.magenta
print("Have you seen Tom, btw?") Colour.white Highlight.white
Colour.grey Highlight.grey
Style.bold Style.underline
Multiple if Statements
if name == "Joan":
print("My name is Joan too!")
if name == "John":
print("My brother's name is John.")
if name == "Hugo":
print("My best friend is called Hugo.")
print("Bye now!")
Repeating Code (goto Loops)
from csinsc import * # using code from