/
game_01_comments.py
47 lines (42 loc) · 1.68 KB
/
game_01_comments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Some notes:
# a) The '#' symbols mean comments and Python will ignore these lines of code
# b) When indenting code, it's always "4 spaces". Some editors allow you to use tabs
# and it converts it to 4 spaces automatically for you.
#
# This program just outputs text (or string) "hello" to the screen
# This is a function called main
def say_hello():
'''
Prints hello string when run from command line
'''
print("hello")
# 1. To run this program, open your terminal.
# 2. Type the following: python game_01.py
# 3. Hit return
# :::: Activities :::
# Open your Python interpretor by typing python and hit return, and >>> should appear.
# Try using single quotes instead of double quotes
# What happens when you mix quotes. Examples to try:-
# print("hello')
# print('hello")
# print('I'm going outside')
# How will you fix the print statements?
# When Python encounters a quote, it expects it to be closed with the same quote
# e.g. you open with a single quote, you close it with a single quote
#
# Try printing numbers
#
# CONCATENATION - joins up the string
# print("hello, " + "how are you")
# You can't mix numbers and strings, you'll get an error, e.g. print("hello" + 1)
#
# ESCAPING STRINGS - use a \
# The following example should now work
# print('I\'m going outside')
# Reference in docs: https://docs.python.org/3/library/__main__.html
# If you run this python file it will have a standalone application that
# has it's defined entry point and won't execute everything in the Python
# file all at once.
if __name__ == '__main__':
# This calls a function called "main"
say_hello()