Section 1

Preview this deck

print(max(pi_tuple))

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (136)

Section 1

(50 cards)

print(max(pi_tuple))

Front

how do you get the largest item in a tuple named 'pi_tuple'

Back

grocery_list.append('Onions')

Front

how do you add 'Onions' at the end of the list named 'grocery_list'

Back

del super_villains['Fiddler']

Front

how do you delete an entry with key 'Fiddler' from a dictionary named 'super_villains'

Back

new_list = list(pi_tuple)

Front

how do you convert a tuple named 'pi_tuple' into a list named 'new_list'

Back

dictionary

Front

a data type that has a unique key for each value; similar to list but you cannot join them together

Back

+ - / % * //

Front

7 arithmetic operations

Back

grocery_list.remove('Pickle')

Front

how do you delete the item 'Pickle' from the list named 'grocery_list'

Back

-3

Front

1+2-3*2

Back

#

Front

Tag for a single line comment

Back

print(len(pi_tuple))

Front

how do you get the number of items in a tuple named 'pi_tuple'

Back

pip3 install package_name

Front

how do you install a python package named 'package_name'

Back

print(len(super_villains))

Front

how do you print the number of key=>value pairs in a dictionary named 'super_villains'

Back

sudo apt-get install build-essential libssl-dev libffi-dev python-dev

Front

few more packages and development tools to install to ensure robust set-up of programming environment

Back

print(super_villains.get('Pied Piper'))

Front

another way to display the value of key 'Pied Piper' from the dictionary named 'super_villains'

Back

super_villains = {'Fiddler': 'Isaac Bowin', 'Captain Cold': 'Leonard Snart', 'Weather Wizard': 'Mark Mardon', 'Mirror Master': 'Sam Scudder', 'Pied Piper': 'Thomas Peterson'}

Front

how do you create a dictionary named 'super_villains' containing the following key=>value pairs: 'Fiddler' => 'Isaac Bowin' 'Captain Cold' => 'Leonard Snart' 'Weather Wizard' => 'Mark Mardon' 'Mirror Master' => 'Sam Scudder' 'Pied Piper' => 'Thomas Peterson'

Back

print(min(to_do_list2))

Front

how do you print the smallest item, i.e., whatever comes first alphabetically, in the list named 'to_do_list2'

Back

grocery_list = ['Juice', 'Tomatoes', 'Potatoes', 'Bananas']

Front

example on how to declare a list 'grocery_list' to contain 'Juice', 'Tomatoes', 'Potatoes', 'Bananas'

Back

super_villains['Pied Piper'] = 'Hartley Rathaway'

Front

how do you change the value of key 'Pied Piper' into 'Hartley Rathaway' in the dictionary named 'super_villains'

Back

+

Front

operator to concatenate strings

Back

pip

Front

manages software packages for python

Back

maps

Front

another term for the data type 'dictionary'

Back

print(max(to_do_list2))

Front

how do you print the largest item, i.e., whatever comes last alphabetically, in the list named 'to_do_list2'

Back

del grocery_list[4]

Front

how do you delete a specific item, say the 5th item, in a list named 'grocery_list'

Back

print(super_villains['Captain Cold'])

Front

how do you display the value of the key 'Captain Cold' in a dictionary named 'super_villains'

Back

print(len(to_do_list2))

Front

how do you print how many items a list named 'to_do_list2' has

Back

//

Front

integer division operator

Back

'''

Front

Tag for a multiline comment

Back

sudo apt-get install -y python3-pip

Front

how do you install pip

Back

print(grocery_list[1:3])

Front

how do you print elements '1' to '3' of the list 'grocery_list'

Back

print(to_do_list[1][1])

Front

how do you display the 2nd item in the 2nd list of a list named to_do_list

Back

pip3 install numpy

Front

how do you install the python package 'NumPy'

Back

numbers strings lists tuples dictionaries

Front

5 main data types in python

Back

super_villains_keys = super_villains.keys()

Front

how do you create a list named 'super_villains_keys' from a dictionary named 'super_villains'

Back

pi_tuple = (3,1,4,1,5,9)

Front

how do you create a tuple named 'pi_tuple' that contains the following items: 3,1,4,1,5,9

Back

print ("Hello World")

Front

Print the text "Hello World" on the console

Back

print('First Item', grocery_list[0])

Front

how do you print "First Item" and appended to that is the first item in the list 'grocery_list'

Back

new_string = quote + multi_line_quote

Front

example concatenating strings named 'quote' and 'multi_line_quote' to a new string 'new_string'

Back

print("I don't like ", end="")

Front

how to use print getting rid of the new lines

Back

grocery_list.insert(1, 'Pickle')

Front

how do you add 'Pickle' as the 2nd item in the list named 'grocery_list'

Back

print('
' * 5)

Front

print 5 new lines

Back

to_do_list = [other_events, grocery_list]

Front

an example of how to make a list 'to_do_list' from 2 lists 'other_events' and 'grocery_list'

Back

grocery_list[0] = "Green Juice"

Front

how do you change the value of the first item in the list 'grocery_list' to "Green Juice"

Back

name = "Derek"

Front

Store "Derek" to a variable named 'name'

Back

new_tuple = tuple(new_list)

Front

how do you create a tuple named 'new_tuple' from a list named 'new_list'

Back

grocery_list.reverse()

Front

how do you sort the items in a list named 'grocery_list' in descending order

Back

NumPy

Front

a scientific computing python package

Back

to_do_list2 = other_events + grocery_list

Front

how do you combine 2 lists named 'other_events' and 'grocery_list' into a new list named 'to_do_list2'

Back

grocery_list.sort()

Front

how do you sort the items in a list named 'grocery_list' alphabetically in ascending order

Back

print(min(pi_tuple))

Front

how do you get the smallest item in a tuple named 'pi_tuple'

Back

tuple

Front

unlike the list, you cannot change this data type after it is created

Back

Section 2

(50 cards)

if (age >= 1) and (age <= 18): print("birthday") elif (age == 21) or (age >= 65): print("birthday") elif not(age == 30): print("no birthday") else: print("birthday party")

Front

implement the following logic without space preceding ":" symbol: age between 1 to 18 (inclusive) display "birthday" age is 21 or more than 65 (inclusive) display "birthday" age is not 30 display "no birthday" otherwise, display "birthday party"

Back

long_string.strip()

Front

how do you remove trailing spaces in a string named 'long_string'

Back

print(super_villains.values())

Front

how do you display the values of a dictionary named 'super_villains'

Back

long_string.replace("Floor", "Ground")

Front

in a string named 'long_string', how do you replace the word "Floor" with "Ground"

Back

for x in range(0, 10): print(x, ' ', end="") print(10-x, ' ', end="")

Front

using the 'for' loop, display '0 10 1 9 2 8 3 7 4 6 5 5 6 4 7 3 8 2 9 1 '

Back

print(long_string.capitalize())

Front

how do you display the string named 'long_string' with the first letter capitalised

Back

equally indented space

Front

what is used to group blocks of code in a python

Back

def

Front

keyword to define a function

Back

len(long_string)

Front

how do you determine the number of characters a string has

Back

Hello Michael

Front

if the user types in 'Michael', what is displayed when the following code is executed: print('What is your name') name = sys.stdin.readline() print('Hello', name)

Back

%c

Front

print character formatting placeholder

Back

function

Front

used to write more readable code

Back

test_file.name

Front

how do you determine the name of a file given the file handle named 'test_file'

Back

test_file.close()

Front

how do you close an open file handle named 'test_file'

Back

name = sys.stdin.readline()

Front

how do you get the character typed by the user at the command line and assign it to a variable named 'name'

Back

test_file.write(bytes("Write me to the file
", "UTF-8"))

Front

how do you write the UTF8 characters "Write me to the file
" given the file handle named 'test_file'

Back

while

Front

loop structure to use when you have no idea how many times you need to loop

Back

for x in range(0, 10): print(x, ' ', end="")

Front

using the 'for' loop, display '0 1 2 3 4 5 6 7 8 9 '

Back

long_string.isalnum()

Front

how do you check if a string named 'long_string' contains only alphabetical and numeric characters

Back

02468

Front

what is the output of the following code script: i = 0; while(i <= 20): if(i%2 == 0): print(i, end="") elif(i == 9): break else: i += 1 continue i += 1 # This is equivalent to i = i + 1

Back

%.5f

Front

print floating number formatting placeholder, e.g., 5 decimal places

Back

I wi

Front

What is the output of the following code: long_string = "I will catch you if you fall - The Floor" print(long_string[0:4])

Back

X is my favorite letter and my number 1 number is 0.14000

Front

what is the output of the following code: print("%c is my %s letter and my number %d number is %.5f" % ('X', 'favorite', 1, .14))

Back

for x in range(0,3): for y in range(0,3): print(num_list[x][y])

Front

using the 'for' loop, display all sub-items in a list named 'num_list' that contains the following: [[1,2,3],[10,20,30],[100,200,300]]

Back

print(long_string[0:4])

Front

how do you print the first 4 characters of a string named 'long_string'

Back

for y in grocery_list: print(y)

Front

using the 'for' loop, display the items in a list named 'grocery_list'

Back

if age >= 21 : print('tractor trailer') elif age >= 16 : print('car') else : print("not old enough")

Front

implement the following logic with space preceding the ":" symbol: age >= 21 display "tractor trailer" age >= 16 display "car" age < 16 display "not old enough"

Back

random_num = random.randrange(0,100)

Front

how do you create a random number from 0 to 99 and assign it to a variable named 'random_num'

Back

values = super_villains.values()

Front

how do you create a list named 'values' from the values of a dictionary named 'super_villains'

Back

print(long_string[:-5])

Front

how do you print everything up to the last 5 characters of a string named 'long_string'

Back

35

Front

what is the output of the following code: long_string = "I will catch you if you fall - The Floor" print(long_string.find("Floor"))

Back

if else elif

Front

conditional that performs different actions based on different conditions

Back

quote_list = long_string.split(" ")

Front

how do you explode the string named 'long_string' into a list named 'quote_list' at the space delimiter " "

Back

Floor

Front

what is the output of the following code: long_string = "I will catch you if you fall - The Floor" print(long_string[-5:])

Back

long_string.isalpha()

Front

how do you check if a string named 'long_string' only contains alphabetical characters

Back

random_num = random.randrange(0,100) while(random_num != 15): print(random_num) random_num = random.randrange(0,100)

Front

keep displaying a random number between 0 and 99 until a number 15 is randomly found

Back

for x in [2,4,6,8,10]: print (x)

Front

using the 'for' loop, display the numbers 2,4,6,8,10

Back

%s

Front

print string formatting placeholder

Back

I will catch you if you fall - The

Front

what is the output of the following code: long_string = "I will catch you if you fall - The Floor" print(long_string[:-5])

Back

== != > >= < <=

Front

6 conditionals

Back

test_file = open("test.txt", "ab+)

Front

how do you open and get the handle named 'test_file' to a file named 'test.txt' for reading and append

Back

ab+

Front

what is the console output of the following code (aside from a file being created): test_file = open("test.txt", "ab+") print(test_file.mode) test_file.write(bytes("Write me to the file
", "UTF-8")) test_file.close()

Back

%d

Front

print integer formatting placeholder

Back

5

Front

what is the output of the following code: def addNumber(fNum, lNum): sumNum = fNum + lNum return sumNum print(addNumber(1, 4))

Back

print(long_string[-5:])

Front

how do you print the last 5 characters of a string named 'long_string'

Back

I wi be there

Front

what is the output of the following code: long_string = "I will catch you if you fall - The Floor" print(long_string[:4] + " be there")

Back

and or not

Front

logical operators

Back

print(super_villains.keys())

Front

how do you display the keys of a dictionary named 'super_villains'

Back

test_file.mode

Front

how do you determine the mode upon which a file was opened given the file handle 'test_file'

Back

print(long_string.find("Floor"))

Front

how do you find the index value for the first occurrence of a string "Floor" in the string named 'long_string'

Back

Section 3

(36 cards)

test.txt

Front

what is the console output of the following code: test_file = open("test.txt", "ab+") print(test_file.name) test_file.write(bytes("Write me to the file
", "UTF-8")) test_file.close()

Back

rm -rf my_project

Front

how do you delete a virtual environment named "my_project"?

Back

virtualenv my_project

Front

how do you create a "virtualenv" assuming the active subfolder is "/my_project"

Back

virtualenv --version

Front

how do you test if "virtualenv" works

Back

os.remove("test.txt")

Front

how do you delete a file named "test.txt"

Back

__name = None

Front

how do you initialize a local variable in a class to nothing

Back

source my_project/bin/activate

Front

To begin using the virtual environment, it needs to be activated. How do you do this using a virtual environment named "my_project"

Back

pip install -r requirements.txt --trusted-host pypi.python.org

Front

Later it will be easier for a different developer (or you, if you need to re-create the environment) to install the same packages using the same versions enumerated in the "requirements.txt" file:

Back

pip list

Front

You can see the list of installed packages without the requirements format using "___".

Back

export WORKON_HOME=C:\works\storeapi

Front

how do you designate "C:\works\storeapi" to be the home folder of all virtual environments

Back

Whiskers is 33 cm tall and 10 kilograms and says Meow

Front

what is the output of the following code: 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 # The constructor is called to set up or initialize an object # self allows an object to refer to itself inside of the class def __init__(self, name, height, weight, sound): self.__name = name self.__height = height self.__weight = weight self.__sound = sound def set_name(self, name): self.__name = name def set_height(self, height): self.__height = height def set_weight(self, height): self.__height = height def set_sound(self, sound): self.__sound = sound 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) # How to create a Animal object cat = Animal('Whiskers', 33, 10, 'Meow') print(cat.toString())

Back

def set_name(self, name): self.__name = name

Front

how do you declare a class function 'set_name'

Back

RuffRuffRuffRuff

Front

what is the output of the following code: class Dog(Animal): __owner = None # You don't have to require attributes to be sent # This allows for method overloading def multiple_sounds(self, how_many=None): if how_many is None: print(self.get_sound) else: print(self.get_sound() * how_many) spot = Dog("Spot", 53, 27, "Ruff", "Derek") spot.multiple_sounds(4)

Back

polymorphism

Front

allows us to refer to objects as their superclass and the correct functions are called automatically

Back

pip install numpy-1.13.0+mkl-cp27-cp27m-win_amd64.whl

Front

how do you install a "numpy-1.13.0+mkl-cp27-cp27m-win_amd64.whl"?

Back

virtualenv storeapi_env

Front

will create a folder named "storeapi_env" in the current directory which will contain the Python executable files, and a copy of the pip library which you can use to install other packages

Back

class Dog(Animal):

Front

how do you create a class 'Dog' that inherits from the 'Animal' class

Back

Dog

Front

what is the output of the following code: class AnimalTesting: def get_type(self, animal): animal.get_type() test_animals = AnimalTesting() spot = Dog("Spot", 53, 27, "Ruff", "Derek") test_animals.get_type(spot )

Back

test_file = open("test.txt", "r+")

Front

how do you open a file handle named 'test_file' to a file named 'test.txt' in reading and write mode

Back

virtualenv

Front

a tool to create isolated Python environments. virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need.

Back

source storeapi_env/Scripts/activate

Front

In Windows 10, how do you activate an environment named "storeapi_env"?

Back

Spot is 53 cm tall and 27 kilograms and says Ruff. His owner is Derek

Front

what is the output of the following code: class Dog(Animal): __owner = None def __init__(self, name, height, weight, sound, owner): self.__owner = owner self.__animal_type = None # How to call the super class constructor super(Dog, self).__init__(name, height, weight, sound) def set_owner(self, owner): self.__owner = owner def get_owner(self): return self.__owner def get_type(self): print("Dog") # We can overwrite functions in the super class def toString(self): return "{} is {} cm tall and {} kilograms and says {}. His owner is {}".format(self.get_name(), self.get_height(), self.get_weight(), self.get_sound(), self.__owner) # You don't have to require attributes to be sent # This allows for method overloading def multiple_sounds(self, how_many=None): if how_many is None: print(self.get_sound) else: print(self.get_sound() * how_many) spot = Dog("Spot", 53, 27, "Ruff", "Derek") print(spot.toString())

Back

Animal

Front

what is the output of the following code: class AnimalTesting: def get_type(self, animal): animal.get_type() test_animals = AnimalTesting() cat = Animal('Whiskers', 33, 10, 'Meow') test_animals.get_type(cat)

Back

deactivate

Front

If you are done working in the virtual environment for the moment, you can deactivate it. How do you do this?

Back

text_in_file = test_file.read()

Front

how do you get the content of a file with a file handle 'test_file' and assign it to a variable 'text_in_file'

Back

cat = Animal('Whiskers', 33, 10, 'Meow')

Front

how do you get an instance of a class named 'Animal' whose constructor require the parameters: name, height, weight, sound

Back

def toString(self): return "{} is {} cm tall and {} kilograms and says {}".format(self.__name, self.__height, self.__weight, self.__sound)

Front

how do you return a formatted string in a class function 'toString'

Back

def multiple_sounds(self, how_many=None):

Front

how do you declare a class function named 'multiple_sounds' that has an optional parameter 'how_many'

Back

pip install --trusted-host pypi.python.org virtualenvwrapper

Front

how do you install the virtualenvwrapper

Back

pip freeze > requirements.txt

Front

This will create a "requirements.txt" file, which contains a simple list of all the packages in the current environment, and their respective versions.

Back

__init(self)__

Front

what is the name of the class constructor

Back

Write me to the file

Front

what is the output of the following code if the file "test.txt" has the entry "Write me to the file" test_file = open("test.txt", "r+") text_in_file = test_file.read() print(text_in_file) test_file.close()

Back

super(Dog, self).__init__(name, height, weight, sound)

Front

in a class named 'Dog', how do you call its super class 'Animal' whose constructor requires the parameters name, height, weight, sound

Back

virtualenvwrapper

Front

provides a set of commands which makes working with virtual environments much more pleasant. It also places all your virtual environments in one place.

Back

pip install --trusted-host pypi.python.org virtualenv

Front

how do you install "virtualenv" using "pip"

Back

class Animal:

Front

how do you declare a class named 'Animal'

Back