Python Basics - Practice

QTM 350: Data Science Computing

Davi Moreira

Introduction


No description has been provided for this image

This topic material is based on the Python Programming for Data Science book and adapted for our purposes in the course.

Exercise

What is 5 to the power of 5?

In [ ]:
# Your answer here.

Exercise

What is the remainder from dividing 73 by 6?

In [ ]:
# Your answer here.

Exercise

How many times does the whole number 3 go into 123? What is the remainder of dividing 123 by 3?

In [ ]:
# Your answer here.

Exercise

Split the following string into a list by splitting on the space character:

In [ ]:
s = "MDS is going virtual!"

# Your answer here.

Exercise

Given the following variables:

thing = "light"
speed = 299792458  # m/s

Use f-strings to print:

The speed of light is 2.997925e+08 m/s.
In [ ]:
# Your answer here.

Exercise

Given this nested list, use indexing to grab the word "MDS":

In [ ]:
l = [10, [3, 4], [5, [100, 200, ["MDS"]], 23, 11], 1, 7]

# Your answer here.

Exercise

Given this nest dictionary grab the word "MDS":

In [ ]:
d = {
    "outer": [
        1,
        2,
        3,
        {"inner": ["this", "is", "inception", {"inner_inner": [1, 2, 3, "MDS"]}]},
    ]
}

# Your answer here.

Exercise

Why does the following cell return an error?

In [ ]:
t = (1, 2, 3, 4, 5)
t[-1] = 6

Exercise

Use string methods to extract the website domain from an email, e.g., from the string "davi.moreira@fakemail.com", you should extract "fakemail".

In [ ]:
email = "davi.moreira@fakemail.com"

# Your answer here.

Exercise

Given the variable language which contains a string, use if/elif/else to write a program that:

  • return "I love snakes!" if language is "python" (any kind of capitalization)
  • return "Are you a pirate?" if language is "R" (any kind of capitalization)
  • else return "What is language?" if language is anything else.
In [ ]:
language = "python"

# Your answer here.
In [ ]:
!jupyter nbconvert _01-py-basics-practice.ipynb --to html --template classic --output 01-py-basics-practice.html

Have fun!