<jupyter_start><jupyter_text>![](../docs/banner.png)  Python Basics**<NAME>, September 2020** These exercises complement [Chapter 1](../chapters/chapter1-basics.ipynb).  Exercises  1. What is 5 to the power of 5?<jupyter_code># Your answer here.<jupyter_output><empty_output><jupyter_text>2. What is the remainder from dividing 73 by 6?<jupyter_code># Your answer here.<jupyter_output><empty_output><jupyter_text>3. How many times does the whole number 3 go into 123? What is the remainder of dividing 123 by 3?<jupyter_code># Your answer here.<jupyter_output><empty_output><jupyter_text>4. Split the following string into a list by splitting on the space character:<jupyter_code>s = "MDS is going virtual!"

# Your answer here.<jupyter_output><empty_output><jupyter_text>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.```<jupyter_code># Your answer here.<jupyter_output><empty_output><jupyter_text>6. Given this nested list, use indexing to grab the word "MDS":<jupyter_code>l = [10, [3, 4], [5, [100, 200, ["MDS"]], 23, 11], 1, 7]

# Your answer here.<jupyter_output><empty_output><jupyter_text>7. Given this nest dictionary grab the word "MDS":<jupyter_code>d = {
    "outer": [
        1,
        2,
        3,
        {"inner": ["this", "is", "inception", {"inner_inner": [1, 2, 3, "MDS"]}]},
    ]
}

# Your answer here.<jupyter_output><empty_output><jupyter_text>8. Why does the following cell return an error?<jupyter_code>t = (1, 2, 3, 4, 5)
t[-1] = 6<jupyter_output><empty_output><jupyter_text>9. Use string methods to extract the website domain from an email, e.g., from the string `"<EMAIL>"`, you should extract `"fakemail"`.<jupyter_code>email = "<EMAIL>"

# Your answer here.<jupyter_output><empty_output><jupyter_text>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.<jupyter_code>language = "python"

# Your answer here.<jupyter_output><empty_output><jupyter_text>Solutions  1. What is 5 to the power of 5?<jupyter_code>5 ** 5<jupyter_output><empty_output><jupyter_text>2. What is the remainder from dividing 73 by 6?<jupyter_code>73 % 6<jupyter_output><empty_output><jupyter_text>3. How many times does the whole number 3 go into 123? What is the remainder of dividing 123 by 3?<jupyter_code>print(1234 // 3)
print(1234 % 3)<jupyter_output>411
1<jupyter_text>4. Split this string on the space character into a list:```s = "MDS is going virtual!"```<jupyter_code>s = "MDS is going virtual!"
s.split()<jupyter_output><empty_output><jupyter_text>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.```<jupyter_code>thing = "light"
speed = 299792458  # m/s
print(f"The speed of {thing} is {speed:2e} m/s.")<jupyter_output>The speed of light is 2.997925e+08 m/s.<jupyter_text>6. Given this nested list, use indexing to grab the word "MDS":<jupyter_code>l = [10,[3,4],[5,[100,200,['MDS']],23,11],1,7]
l[2][1][2]<jupyter_output><empty_output><jupyter_text>7. Given this nest dictionary grab the word "MDS":<jupyter_code>d = {
    "outer": [
        1,
        2,
        3,
        {"inner": ["this", "is", "inception", {"inner_inner": [1, 2, 3, "MDS"]}]},
    ]
}
d['outer'][3]['inner'][3]['inner_inner'][3]<jupyter_output><empty_output><jupyter_text>8. Why does the following cell return an error?<jupyter_code>t = (1, 2, 3, 4, 5)
t[-1] = 6<jupyter_output><empty_output><jupyter_text>Because tuples are immutable!  9. Use string methods to extract the website domain from an email, e.g., from the string `"<EMAIL>"`, you should extract `"fakemail"`.<jupyter_code>email = "<EMAIL>"
email.split("@")[-1].split(".com")[0]<jupyter_output><empty_output><jupyter_text>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.<jupyter_code>language = "python"
if language.lower() == "python":
    print("I love snakes!")
elif language.lower() == "r":
    print("Are you a pirate?")
else:
    print(f"What is {language}?")<jupyter_output>I love snakes!
{'fraction_non_alphanumeric': 0.15289256198347106, 'fraction_numerical': 0.042627229230100046, 'mean_word_length': 5.432167832167832, 'pattern_counts': {'":': 12, '<': 83, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '20', 'dir': 'jupyter-structured-clean-dedup', 'id': '516526', 'license': 'CC0-1.0', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1648, 'n_words': 481, 'path': 'practice-exercises/chapter1-basics-practice.ipynb', 'repo_name': 'unverciftci/python-programming-for-data-science', 'size': '4676'}