Python
What is Python?
Python is a high-level coding language used for data science in industry and research. Learn more below!
Python Resources
Python Online Classes: Online classes on anything and everything Python, beginner to advanced.
Miles Chen UCLA Python Classes Online: All classes taught by Miles Chen are free online. The Stats 21 series is a phenomenal intro to Python.
Data Analysis with Python: Introduction to numpy, pandas, seaborn, and statistical analysis in Python.
Machine Learning with Python: Learn complex data stuctures, networking with libraries and vizulization tecniques.
Workshop Recording: Intro to Python
In the beginning of Winter Quarter 2023, NSDC UCLA hosted an Intro to Python Workshop which went over the basics of the most popular coding languages used in industry and research today. Below is a recording of that workshop as well as python practice problems and solutions.

Intro to Python Optional Practice Problems
Calculate the following by hand, and then check your answer using Python
3 * 4
10 - 3 * 9 / 4
15 * 3 // 6
-12 // 5
(9 – 3(5 + 3)) % 7
Evaluate the following by hand, and then check your answer using Python
5 * 3 > 16
-(1 ** 2) == 2 ** 0
10 % 3 != 1
19 % 4 != 300 / 10 / 10 and False
not 3 ** 4 < 4 **3
2 ** 3 != 7 or 5 < 4 and ‘Arthur’ == ‘Arthur’
True and not (False or True)
not not True or False and not True
Modify the false statements so that they return true
Task: Extract ‘World’ from ‘Hello World!’
Task: construct a series of conditional statements to do the following:
If your grade is less than a 60, you receive a letter grade of ‘F’
If your grade is between 60 and 69, you receive a letter grade of ‘D’
If your grade is between 70 and 79, you receive a letter grade of ‘C’
If your grade is between 80 and 89, you receive a letter grade of ‘B’
If your grade is between 90 and 97, you receive a letter grade of ‘A’
If you grade is between 98 and 100, you receive a letter grade of ‘A+’
Task: Do some manipulations with a list of the days of the week
First, initialize an empty list ([]) and store it in a variable called daysOfWeek
Append all the days of the week to daysOfWeek, starting with Monday
Splice out the weekdays (Mon-Fri) and store it in a variable called weekdays
Splice out the weekend (Sat-Sun) and store it in a variable called weekend
Task: Make a dictionary of your favorite show called favShow!
Your dictionary should have keys such as ’Name’, ‘Number of Episodes’, etc.
Print out the name of the show using favShow in this format:
The name of my favorite show is [Name of show]
Change the values of your dictionary to the details of another show you like
Task: Print out the first ten multiples of 5
First solve this using a while loop
Then use a for loop
Intro to Python Optional Practice Problems Solutions
Task: Do the following by hand, and then check it using Python
3 * 4 = 12
10 - 3 * 9 / 4 = 3.25
15 * 3 // 6 = 7
-12 // 5 = -3
(9 – 3(5 + 3)) % 7 = 6
Evaluate the following by hand, and then check your answer using Python
5 * 3 > 16 TRUE
-(1 ** 2) == -2 ** 0 FALSE
10 % 3 != 1 FALSE
19 % 4 != 300 / 10 / 10 and True FALSE
not 3 ** 4 < 4 **3 TRUE
2 ** 3 != 7 or 5 < 4 and ‘Arthur’ == ‘Arthur’ TRUE
True and not (False or True) FALSE
not not True or False and not True TRUE
Task: Extract ‘World’ from ‘Hello World!’
‘Hello World!’[6:11]
Task: construct a series of conditional statements to do the following:
If your grade is less than a 60, you receive a letter grade of ‘F’
if grade < 60:
letterGrade = ‘F’
If your grade is between 60 and 69, you receive a letter grade of ‘D’
if grade >= 60 and grade <= 69:
letterGrade = ‘D’
If your grade is between 70 and 79, you receive a letter grade of ‘C’
if grade >= 70 and grade <= 79:
letterGrade = ‘C’
If your grade is between 80 and 89, you receive a letter grade of ‘B’
if grade >= 80 and grade <= 89:
letterGrade = ‘B’
If your grade is between 90 and 97, you receive a letter grade of ‘A’
if grade >= 90 and grade <= 97:
letterGrade = ‘A’
If you grade is between 98 and 100, you receive a letter grade of ‘A+’
if grade >= 98 and grade <= 100:
letterGrade = ‘A+’
Task: Do some manipulations with a list of the days of the week
First, initialize an empty list ([]) and store it in a variable called daysOfWeek
daysOfWeek = []
Append all the days of the week to daysOfWeek, starting with Monday
daysOfWeek.append(“Monday”)
daysOfWeek.append(“Tuesday”)
daysOfWeek.append(“Wednesday”)
daysOfWeek.append(“Thursday”)
daysOfWeek.append(“Friday”)
daysOfWeek.append(“Saturday”)
daysOfWeek.append(“Sunday”)
Splice out the weekdays (Mon-Fri) and store it in a variable called weekdays
weekdays = daysOfWeek[0:6]
Splice out the weekend (Sat-Sun) and store it in a variable called weekend
weekend = daysOfWeek[6]
Task: Make a dictionary of your favorite show called favShow!
Your dictionary should have keys such as ’Name’, ‘Number of Episodes’, etc.
favShow = {‘Name’: Secret Garden, ‘Number of Episodes’: 20, ‘Lead Actor’: ‘Hyun Bin’}
Print out the name of the show using favShow in this format:
The name of my favorite show is [Name of show]
print(“The name of my favorite show is “ + favShow[‘Name’])
Change the values of your dictionary to the details of another show you like
favShow[‘Name’] = Jane the Virgin
favShow[‘Number of Episodes’] = 100
favShow[‘Lead Actor’] = ‘Justin Baldoni’
Task: Print out the first ten multiples of 5
First solve this using a while loop:
i = 1
while i < 11:
print(5**i)
Then use a for loop:
for i in range(1,11):
print(5**i)
Workshop Recording: Advanced Python and NumPy
In the middle of Winter Quarter 2023, NSDC UCLA hosted an Advanced Python & NumPy Workshop which reviewed object-oriented programming skills and taught the basics of data processing. Below is a recording of that workshop as well as Python practice problems and answers.

Advanced Python and NumPy Optional Practice Problems
Create a Person class with an initializer that defines a first name, last name, gender, and occupation variables. Include an introduce() function that prints out an introduction for the person using any of the information included as member variables.
Now, create a person that is yourself and use the introduce function to introduce yourself
Create a Job parent class with salary, location, and company name variables and a work() function that prints out “I’m doing work”. Then, create two child classes called Engineer and Accountant that each have their own unique functions. These functions can do anything you’d like.
Create a NumPy array [10, 20, 30, 40] from a normal Python list
Turn a NumPy array [1, 2, 3] into [12, 24, 36]
Create a 4 by 5 NumPy array of ones and then reshape it into a 10 by 2 array
Mask a ten-element array to only include 3, 6, and 9
Advanced Python and NumPy Optional Practice Problems Solutions
Create a Person class with an initializer that defines a first name, last name, gender, and occupation variables. Include an introduce() function that prints out an introduction for the person using any of the information included as member variables.
class Person:
def __init__(self, firstName, lastName, gender, occupation):
self.firstName = firstName
self.lastName = lastName
self.gender = gender
self.occupation = occupation
def introduce():
print(“Hello, I am “ + self.firstName + “ “ + self.lastName + ”and I
am a ” + self.occupation)
Now, create a person that is yourself and use the introduce function to introduce yourself
anna = Person(“Anna”, “Guo”, “Female”, “Student”)
anna.introduce()
Create a Job parent class with salary, location, and company name variables and a work() function that prints out “I’m doing work”. Then, create two child classes called Engineer and Accountant that each have their own unique functions. These functions can do anything you’d like.
class Job():
def __init__(self, salary, location, companyName):
self.salary = salary
self.location = location
self.companyName = companyName
def work(self):
print(“I am doing work.”)
class Engineer(Job):
def build(self):
print(“I am building stuff.”)
class Accountant(Job):
def doTaxes(self):
print(“I am doing taxes.”)
Create a NumPy array [10, 20, 30, 40] from a normal Python list
L = [10, 20, 30, 40]
np_L = np.array(L)
Turn a NumPy array [1, 2, 3] into [12, 24, 36]
l1 = np.array([1, 2, 3])
l1 = 12*l1
Create a 4 by 5 NumPy array of ones and then reshape it into a 10 by 2 array
l2 = np.ones((4, 5))
l2.reshape(10, 2)
Mask a ten-element array to only include 3, 6, and 9
L = np.arange(10)
L[L%3 == 0]