In Python, a variable must be declared/created before it is assigned a value:
True or False?
False
What is the difference between a for loop and a while loop?
For loop->runs for a certain amount of time
While loop -> can run for an uncertain amount of time
What is a class?
A class is a blueprint from which different objects are created.
What is an array?
An array is a collection of values or items
Which of the following statements assigns the value 100 to the variable x in Python:
X = 100
X :=100
X << 100
X == 100
x = 100
How would you call a function?
Lets just say I create a function:
def friend():
#put some code in this and I am printing it to output
Now what I do to call it?
1. Come outside the function
2. type the function name like this friend()
def friend():
#some code
friend()
Constructor
What is the difference between a numpy array and an array?
array -> 1 dimensional
What are the three variable types we covered in class?
String, Integer, Boolean
Char, int, bool
Str, int, boolean
String, Integer, Boolean
isAlive = False
While not isAlive:
print(“Hi)
Why won’t this while loop ever stop?
This is because we never made a condition to make isAlive True
class NBA:
def __init__(self, name, ball):
self.name = name
self.ball = ball
def game(self):
print("Let's start the game!")
def make_noise(self):
print("DEFENSE")
basketball_game = NBA("Warriors", "basketball")
How can I access the name of the basketball's team?
How can I add 5 to all the values in a 1 Dimensional array?
1. Create empty list/array to store the sums
2. Use for loop that stops when it reaches the end of the array and appends array[i] + 5 every time the for loop execute like :
for i in range(len(arr)):
num2.append(arr + 5)
Number_of_doughnuts = 4
If number_of_doghnuts > 4:
Number_of_doughnuts -= 3
Else:
Number_of_doughnuts +=9
What would this print if I typed print(Number_of_doughnuts)
13
How would you call a function?
Lets just say I create a function:
def friend():
value = 5
return value
Now what I do to call it?
How about if there was an argument like:
def friend(number):
value = number
return value
1. Outside the function initialize the function's name to a variable:
function = friend()
print(function)
2. function = friend(any value like 5)
print(function)
class NBA:
def __init__(self, teamName, ball):
self.name = teamName
self.ball = ball
def game(self):
print("Let's start the game!")
def make_noise(self):
print("DEFENSE")
basketball_game = NBA("Warriors", "basketball")
class Stephen_Curry(NBA):
def three_pointer():
print("Stephen curry shoots the 3 pointer!")
How can I make Stephen curry play a basketball game , I want to let stephen curry do the game function from above?
create Stephen curry object like :
player = Stephen_Curry("Warriors", "basketball")
player.game()
Machine learning is used to predict or conclude?
predict
number = input("Enter a number")
if number == 14:
print("hi")
else:
print("no")
What would be printed out if I ran this program?
It would give me an error because I didn't convert number to an integer
Random = random.randint(0,3)
That is all I have written. When I run this code what should I get?
An error because I didn't import random
I want to create a car object that has an accelerator, brake attribute and a move function.
Take one minute to write this real quick
class car:
def __init__(self, accelerator, brake):
self.accelerator = accelerator
self.brake = brake
def move(self):
print("car is moving")
Car = car("accelator", "brake")
What are the names of these two splits?
Train and test