# This is a comment
name = "Julius" # This is also a comment but after a code
x = 1 + 2 # Addition (3)
x = 2 - 2 # Subtraction (0)
x = 3 * 2 # Multiplication (6)
x = 4 / 2 # Division (2)
x = 5 % 2 # Modulus (1)
x = 6 ** 2 # Exponentiation (36)
x = 1
x += 10
# The above is equivalent to the following
x = 1
x = x + 10
# Variable names can be letters/numbers, underscore should be used instead of spaces
first_name = "Daniel" # String as variable type
age = 20 # Integer as variable type
1st_purchase = True # Boolean as variable type
order_subtotal = 249.9 # Float as variable type

# The value assigned to a variable can be changed
age = 21
# Both single and double quotation mark can be used
user_name = "Jason"
user_id = 'AG3K27L0'

# Use backslash '\\' to indicate the string continues on next line
user_comment = "This website is awful!! It is lack of visual aids and \\
the 'news' section is not updated regularly!!"
greeting = "Hello, "
question = "what is your name?"
greet_and_ask = greeting + question # "Hello, what is your name?"

# += operator can also be used to concatenate strings
greet_and_ask = "Hello, "
greet_and_ask += "what is your name?"
# greet_and_ask is now the string "Hello, what is your name?"
SyntaxError: invalid syntax
ZeroDivisionError: division by zero
NameError: name 'user_naame' is not defined
# Any number that contains a decimal portion is a floating type number
pi = 3.14159265
e = 2.71828182
bp = 0.0001
# This function is used to output text, numbers etc. to the console
print("Hello World!")
print(365)
e = 2.71828182
print(e)
x = 1
y = 9

x < y # Less than (True)
x > y # Greater than (False)
x <= y # Less than or equal to (True)
x >= y # Greater than or equal to (False)
# The equal operator '==', is used to compare two values
# Returns True if both values are the same, False otherwise
1+1 == 2*1 # True
5-1 == 3+2 # False
# The not equal operator '!=', is used to compare two values
# Returns True if the two values are not the same, False otherwise
1+1 != 2*1 # False
5-1 != 3+2 # True
# or operator returns True if at least one of expressions returns True
True or False # True
False or False # False
True or True # True
8 < 3 or 4 > 1 # True

# and operator returns True if both of the expressions return True
True and False # False
False and False # False
True and True # True
8 < 3 and 4 > 1 # False
# not operator returns the inverse value of an expression
not True # False
not False # True
not 1>3 # True
not 2==2 # False
if x == y:
	print("x is equal to y")
elif x > y:
	print("x is greater than y")
else:
	print("x is smaller than y")
try: # The codes below will stop running if a error is raised
	x = 4/0
	print(x)
except: # The codes below this will run if the above raises an error
	print('Your code raised an error!')
# List values are placed within square brackets [] and separated by commas
odd_num = [1, 3, 5, 7, 9]
even_num = [2, 4, 6, 8, 10]

# List values can be repeated
repeated = [1, 1, 2, 2, 3, 3]

# A list can be empty
empty_list = []

# A list can contain multiple types of data
user_info = ['James', 'Bond', 35, True]

# A list can contain another list
all_user_info = [['James', 'Bond', 35, True], ['Harry', 'Potter', 17, False]]
user_info = ['James', 'Bond', 35, True]

# Python lists are zero-indexed, the first element in a list has the index 0
# Access a list element by using the notation: list[index]
user_info[0] # 'James'
user_info[3] # True

# Using negative indices can retrieve the element starting from the last element
user_info[-1] # True
user_info[-4] # 'James'

# You can access multiple list elements (slicing) by using: list[start:end]
# It will contain the start element and everything until but excluding end element
user_info[1:3] # ['Bond', 35]
# By leaving out the end index, the slice contains elements after the start element
user_info[1:] # ['Bond', 35, True]
# By leaving out the start index, it contains everything from the first element
# until but excluding the end element
user_info[:2] # ['James', 'Bond']
# You can use negative indices as well
user_info[-3:-1] # ['Bond', 35]
all_user_info = [['James', 'Bond', 35, True], ['Harry', 'Potter', 17, False]]

# Accessing 2D list elements
all_user_info[0][3] # True
all_user_info[1][1] # 'Potter'

# Modifying 2D list elements
all_user_info[1][2] = 18
# Use + to add lists together 
first_order = ['coca cola', 'cheese burger']
second_order = ['fanta', 'chicken nuggets']
all_orders = first_order + second_order
print(all_orders)
# Result should be: ['coca cola', 'cheese burger', 'fanta', 'chicken nuggets']

# To add a single item, you can either use .append() or + another list
all_orders.append('milk shake')
all_orders += ['milk shake']
# Both of the methods above have the same result