📝 Exercise 01


Exercises

1.

What is 5 to the power of 5?

# Your answer here.

2.

What is the remainder from dividing 73 by 6?

# Your answer here.

3.

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

# Your answer here.

4.

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

s = "MDS is going virtual!"

# Your answer here.

5.

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.
# Your answer here.

6.

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

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

# Your answer here.

7.

Given this nest dictionary grab the word “MDS”:

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

# Your answer here.

8.

Why does the following cell return an error?

t = (1, 2, 3, 4, 5)
t[-1] = 6
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-d668dd5b8bda> in <module>
      1 t = (1, 2, 3, 4, 5)
----> 2 t[-1] = 6

TypeError: 'tuple' object does not support item assignment

9.

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

email = "bruce.wayne@fakemail.com"

# Your answer here.

10.

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.

language = "python"

# Your answer here.