Lists and Tuples
Classes and Objects
Functions
Python Basics
Coding Challenges
100

What’s the difference between a list and a tuple?

Lists are mutable, tuples are not.

100

What is the purpose of the init() function in a class?

Initializes new object and its attributes.

100

What keyword starts a function definition in Python?

"def"

100

What are the four most common data types?

String, Int, Boolean, Float

100

Use a for loop to print each item in this list:
["apple", "banana", "cherry"]

fruits = ["apple", "banana", "cherry"]

for fruit in fruits:

    print(fruit)

200

Write a list that holds three values with three different data types

[<string>, <integer>, <float>, <boolean>]

200

In this line, which is the class and which is the object? truck = Vehicle("UHaul")

Vehicle is class; truck is object.

200

What is a parameter?

A variable used inside a function to accept input

200

What keyword is used to check a condition?

"if"

200

Write a function that takes a list of numbers and prints each one doubled using a loop.

def double_numbers(nums):

    for num in nums:

        print(num * 2)

300

How do you access the last element in a list called ordered_list?

ordered_list[-1]

300

What does this print?
class Cat:
def __init__(self, name): self.name = name
c = Cat("Axel")
print(c.name)

"Axel"

300

What will this function return?
def mystery(x):
if x % 2 == 0: return x // 2
else: return x * 3
mystery(5)

15

300

DAILY DOUBLE: What does this return?
!(5 > 2 and 3 > 1)

False

300

Given a tuple of fruits, use a for loop to print only the fruits that start with the letter "b".

fruits = ("banana", "apple", "blueberry", "orange")

for fruit in fruits:

    if fruit.startswith("b"):

        print(fruit)

400

What does this code print?
nums = [3, 8, 5]
nums[1] = 5
print(nums)

[3, 5, 5]

400

Write a method inside a class that returns the 4th power of an attribute called side. Using the exponent operator.

def area(self):
return self.side ** 4

400

What does this code print and why?
def f(x): x += 1
return x
y = 27
f(y)
print(y)

27 (integers are immutable; x is a copy) 

400

Name 3 boolean logical operators

AND (&&), OR (||), NOT (!)

400

DAILY DOUBLE: Define a class Book with a title and pages. Create a list of 3 books and use a loop to print the titles of books with more than 100 pages.

class Book:
    def __init__(self, title, pages):
        self.title = title
        self.pages = pages
books = [
    Book("Book A", 120),
    Book("Book B", 95),
    Book("Book C", 200)
]

for book in books:
    if book.pages > 100:
        print(book.title)

500

DAILY DOUBLE: What will this print?
nums = [37, 20, 30, 50]
nums.insert(2, 15)
nums.pop()
print(nums)

[37, 20, 15, 30]
Inserts 15 at index 2 -- in between 20 and 30.
pop() will remove the last element(50)

500

Create a class Triangle that stores base and height and has a method area() returning the area.

class Rectangle:
self.base = base
self.height = height
def area(self): return self.base * self.height * 1/2

500

What does this return?
def func(x):
if x > 0: return x + func(x - 1)
else: return 0
print(func(5))

15 --- (5+4+3+2+1+0)

500

How would I get the data type of the variable mystery?

type(mystery)

500

Write a function that takes a list of names and returns a new list containing only the names that are longer than 4 letters.

def long_names(names):

    result = []

    for name in names:

        if len(name) > 4:

            result.append(name)

    return result

M
e
n
u