Import Random Import Sys Import Os
Import Random Import Sys Import Os
Import Random Import Sys Import Os
print("Hello World")
3. '''
This is a multi-line comment
'''
name = "Derek"
print(name)
print(quote + multi_line_quote)
# You can get a subset of the list with [min:up to but not including
max]
print(grocery_list[1:3])
print(to_do_list)
# Get the second item in the second list (Boxes inside of boxes)
print(to_do_list[1][1])
pi_tuple = (3, 1, 4, 1, 5, 9)
print(super_villains['Captain Cold'])
# Delete an entry
del super_villains['Fiddler']
print(super_villains)
# Replace a value
super_villains['Pied Piper'] = 'Hartley Rathaway'
age = 30
if age > 16 :
print('You are old enough to drive')
if age > 16 :
print('You are old enough to drive')
else :
print('You are not old enough to drive')
if age >= 21 :
print('You are old enough to drive a tractor trailer')
elif age >= 16:
print('You are old enough to drive a car')
else :
print('You are not old enough to drive')
# You can combine conditions with logical operators
# Logical Operators: and, or, not
for x in range(0,3):
for y in range(0,3):
print(num_list[x][y])
i += 1
20. # FUNCTIONS -------------
# Functions allow you to reuse and write readable code
# Type def (define), function name and parameters it receives
# return is used to return something to the caller of the
function
def addNumbers(fNum, sNum):
sumNum = fNum + sNum
return sumNum
print(addNumbers(1, 4))
print(subNumbers(1, 4))
21. # USER INPUT -------------
print('What is your name?')
print('Hello', name)
# Replace the first word with the second (Add a number to replace
more)
print(long_string.replace("Floor", "Ground"))
# Remove white space from front and end
print(long_string.strip())
class Animal:
# None signifies the lack of a value
# You can make a variable private by starting it with __
__name = None
__height = None
__weight = None
__sound = None
def get_name(self):
return self.__name
def get_height(self):
return str(self.__height)
def get_weight(self):
return str(self.__weight)
def get_sound(self):
return self.__sound
def get_type(self):
print("Animal")
def toString(self):
return "{} is {} cm tall and {} kilograms and says
{}".format(self.__name, self.__height, self.__weight, self.__sound)
print(cat.toString())