├── README.md
├── SEDS_23
├── day 1_ Monday
│ ├── assignment
│ │ └── ex_1.ipynb
│ └── notebooks
│ │ ├── .ipynb_checkpoints
│ │ ├── 11_var_string_num-checkpoint.ipynb
│ │ ├── 12_lists_tuples-1-checkpoint.ipynb
│ │ └── 13_if_statements-checkpoint.ipynb
│ │ ├── 11_var_string_num.ipynb
│ │ ├── 11_var_string_num_ex1_1.py
│ │ ├── 11_var_string_num_ex1_2.py
│ │ ├── 12_lists_tuples-1.ipynb
│ │ ├── 12_lists_tuples-1_ex1_1.py
│ │ ├── 12_lists_tuples-1_ex1_2.py
│ │ ├── 13_if_statements.ipynb
│ │ ├── 13_if_statements_ex1_1.py
│ │ └── 13_if_statements_ex1_2.py
├── day 2_Tuesday
│ ├── assignment
│ │ └── ex_2.ipynb
│ └── notebooks
│ │ ├── .ipynb_checkpoints
│ │ ├── 21_lists_tuples-2-checkpoint.ipynb
│ │ ├── 22_dictionaries-checkpoint.ipynb
│ │ └── 23_functions-checkpoint.ipynb
│ │ ├── 21_lists_tuples-2.ipynb
│ │ ├── 21_lists_tuples-2_ex1_1.py
│ │ ├── 21_lists_tuples-2_ex1_2.py
│ │ ├── 21_lists_tuples-2_ex1_3.py
│ │ ├── 22_dictionaries.ipynb
│ │ ├── 22_dictionaries_ex1_1.py
│ │ ├── 22_dictionaries_ex1_2.py
│ │ ├── 23_functions.ipynb
│ │ └── 23_functions_ex1_1.py
├── day 3_Wednesday
│ ├── assignment
│ │ ├── customers.csv
│ │ ├── ex_3.ipynb
│ │ ├── pd_books.csv
│ │ ├── pd_customers.csv
│ │ ├── pd_movies.csv
│ │ └── pd_transactions.csv
│ └── notebooks
│ │ ├── 23_functions.ipynb
│ │ ├── 23_functions_ex1_1.py
│ │ ├── 23_functions_ex1_2.py
│ │ ├── 31_OOP.ipynb
│ │ ├── 31_OOP_ex1.py
│ │ ├── 32_data_exploration_part_1.ipynb
│ │ ├── 32_data_exploration_part_1_ex1_1.py
│ │ ├── abstraction.png
│ │ ├── data
│ │ └── adult.csv
│ │ └── inheritance.png
├── day 4_Thursday
│ ├── ex_4.ipynb
│ └── notebooks
│ │ ├── .ipynb_checkpoints
│ │ └── 43_data_collection-checkpoint.ipynb
│ │ ├── 41_data_preprocessing_ex1.py
│ │ ├── 41_data_processing.ipynb
│ │ ├── 42_data_collection.ipynb
│ │ ├── 43_data_collection.ipynb
│ │ ├── data
│ │ ├── adult.csv
│ │ ├── weather.csv
│ │ └── wiki_users.p
│ │ └── my_df.p
├── day 5_Friday
│ ├── assignment
│ │ ├── ex_5.ipynb
│ │ └── mini_project.ipynb
│ └── notebook
│ │ ├── .ipynb_checkpoints
│ │ └── 51_visualization-checkpoint.ipynb
│ │ ├── 51_visualization.ipynb
│ │ └── adult.csv
├── intro to python prep.pdf
└── schedule + syllabus.pdf
├── day 0_ preparation
├── .ipynb_checkpoints
│ └── 0_prep-checkpoint.ipynb
├── 0_prep.ipynb
└── intro to python prep.pdf
├── day 1_ Monday
├── assignment
│ ├── .ipynb_checkpoints
│ │ ├── ex_1-checkpoint.ipynb
│ │ ├── ex_2-checkpoint.ipynb
│ │ └── ex_2_answers-checkpoint.ipynb
│ ├── ex_1.ipynb
│ ├── ex_1_answers.ipynb
│ ├── ex_2.ipynb
│ └── ex_2_answers.ipynb
└── notebooks
│ ├── .ipynb_checkpoints
│ ├── 11_var_string_num-checkpoint.ipynb
│ ├── 12_lists_tuples-1-checkpoint.ipynb
│ ├── 13_if_statements-checkpoint.ipynb
│ ├── 14_lists_tuples-2-checkpoint.ipynb
│ └── 15_dictionaries-checkpoint.ipynb
│ ├── 11_var_string_num.ipynb
│ ├── 11_var_string_num_ex1_1.py
│ ├── 11_var_string_num_ex1_2.py
│ ├── 12_lists_tuples-1.ipynb
│ ├── 12_lists_tuples-1_ex1_1.py
│ ├── 12_lists_tuples-1_ex1_2.py
│ ├── 13_if_statements.ipynb
│ ├── 13_if_statements_ex4_1.py
│ ├── 13_if_statements_ex4_2.py
│ ├── 14_lists_tuples-2.ipynb
│ ├── 14_lists_tuples-2_ex1_1.py
│ ├── 14_lists_tuples-2_ex1_2.py
│ ├── 14_lists_tuples-2_ex1_3.py
│ ├── 15_dictionaries.ipynb
│ ├── 15_dictionaries_ex_1.py
│ └── 15_dictionaries_ex_2.py
├── day 2_ Tuesday
├── assignment
│ ├── .ipynb_checkpoints
│ │ ├── ex_3-checkpoint.ipynb
│ │ └── ex_4-checkpoint.ipynb
│ ├── customers.csv
│ ├── ex_3.ipynb
│ ├── ex_4.ipynb
│ ├── pd_books.csv
│ ├── pd_customers.csv
│ ├── pd_movies.csv
│ └── pd_transactions.csv
└── notebooks
│ ├── .ipynb_checkpoints
│ ├── 21_functions-checkpoint.ipynb
│ ├── 22_data_exploration-checkpoint.ipynb
│ ├── 23_data_processing-checkpoint.ipynb
│ └── 23_functions-checkpoint.ipynb
│ ├── 21_data_exploration_ex_1.py
│ ├── 21_data_exploration_ex_2.py
│ ├── 21_functions.ipynb
│ ├── 21_functions_ex_1.py
│ ├── 21_functions_ex_2.py
│ ├── 21_functions_ex_3.py
│ ├── 22_data_exploration.ipynb
│ ├── 23_data_processing.ipynb
│ ├── 23_data_processing_ex_1.py
│ ├── 23_data_processing_ex_2.py
│ ├── 23_data_processing_ex_3.py
│ ├── 23_data_processing_ex_4.py
│ ├── 24_visualization.ipynb
│ └── data
│ ├── adult.csv
│ └── weather.csv
└── eKOMEX
├── Introduction to Python Schedule (EKOMEX 2024).pdf
├── day 1_ Thursday
├── assignment
│ ├── ex_1.ipynb
│ └── ex_1_answers.ipynb
└── notebooks
│ ├── .ipynb_checkpoints
│ ├── 11_var_string_num-checkpoint.ipynb
│ ├── 12_lists_tuples-1-checkpoint.ipynb
│ ├── 12_lists_tuples-2_OPTIONAL-checkpoint.ipynb
│ └── 13_if_statements-checkpoint.ipynb
│ ├── 11_var_string_num.ipynb
│ ├── 11_var_string_num_ex1_1.py
│ ├── 11_var_string_num_ex1_2.py
│ ├── 12_lists_tuples-1.ipynb
│ ├── 12_lists_tuples-1_ex1_1.py
│ ├── 12_lists_tuples-1_ex1_2.py
│ ├── 12_lists_tuples-2_OPTIONAL.ipynb
│ ├── 12_lists_tuples-2_ex1_1.py
│ ├── 12_lists_tuples-2_ex1_2.py
│ ├── 12_lists_tuples-2_ex1_3.py
│ ├── 13_if_statements.ipynb
│ ├── 13_if_statements_ex1_1.py
│ └── 13_if_statements_ex1_2.py
└── day 2_ Friday
├── assignment
├── ex_2.1.ipynb
├── ex_2.2.ipynb
├── ex_2_1_answers.ipynb
└── ex_2_2_answers.ipynb
└── notebooks
├── .ipynb_checkpoints
├── 12_lists_tuples-2_OPTIONAL-checkpoint.ipynb
├── 21_dictionaries-checkpoint.ipynb
├── 22_dictionaries-checkpoint.ipynb
├── 22_functions-checkpoint.ipynb
├── 23_functions-checkpoint.ipynb
├── 23_visualization-checkpoint.ipynb
└── 24_visualization-checkpoint.ipynb
├── 21_dictionaries.ipynb
├── 22_functions.ipynb
├── 23_visualization.ipynb
├── figure_1.pdf
└── figure_1.png
/README.md:
--------------------------------------------------------------------------------
1 | # Introduction to Programming in Python
2 |
3 | There are three iterations of this course:
4 | - As a block course for the SEDS Master Programming at the University of Konstanz, Winter Semester 23/24 (5 days)
5 | - As an online course for eKOMEX'24 and 25 (2 days)
6 | - As an in-person course at RPTU Landau'24 (2 days)
7 |
8 | Course feedback: https://forms.gle/Yhbi9cBup6okjnim6
9 |
10 | Instructor: Indira Sen
11 |
12 | TAs: Elena Solar, Claire Jordan, Andri Rutschmann, Ana Sanchez Acosta, Dajana Hennig
13 |
--------------------------------------------------------------------------------
/SEDS_23/day 1_ Monday/assignment/ex_1.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "SN-mb9j3Yc1X"
7 | },
8 | "source": [
9 | "# Assignment 1: Python basics and programming fundamentals\n",
10 | "Indira Sen, Claire Jordan, Elena Solar, Andri Rutschmann\n",
11 | "\n",
12 | "Winter Term 2023 / 2024\n",
13 | "\n",
14 | "In this first assignment we will practice how to use Jupyter Notebooks and how to execute Python code. You can score up to 15 points in this assignment. Please submit your solutions inside this notebook in your repository on GitHub. The deadline for submission is on Monday, October 16, 23:59 hours. You will get individual feedback in your repository."
15 | ]
16 | },
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {
20 | "id": "QjcesK4dZSw4"
21 | },
22 | "source": [
23 | "## Ex 1\n",
24 | "\n",
25 | "This exercise covers variables. (total: 6 points)\n",
26 | "\n",
27 | "1. Use some of the arithmetic operations you want and do some calculations. (1 point)\n",
28 | "Bonus: By using `.format()` method to print outputs in such a format \"1+1=2\" (1 point)\n",
29 | "\n",
30 | "2. Define variables a = 16, b = 4 and c = 2.\n",
31 | "\n",
32 | " a.Print result of a/b*c+c (1 points)\n",
33 | "\n",
34 | " b.Do the same calculation but force multiplication to be first and then sum and finally division (by using parentheses) (1 point)\n",
35 | "\n",
36 | "3. Define a sentence and print it's length in a sentence in format of \"The length of 'sentence' is 8.\" (use `.format()` method) (2 points)"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": null,
42 | "metadata": {
43 | "id": "VscuYWW0ZWlM"
44 | },
45 | "outputs": [],
46 | "source": []
47 | },
48 | {
49 | "cell_type": "markdown",
50 | "metadata": {
51 | "id": "SeX48MfjYc1Z"
52 | },
53 | "source": [
54 | "## Ex 2\n",
55 | "This exercise covers variables, lists, and if-statements (total: 5 points)"
56 | ]
57 | },
58 | {
59 | "cell_type": "markdown",
60 | "metadata": {
61 | "id": "0SF9mdqjYc1a"
62 | },
63 | "source": [
64 | "1. Make a list of names that includes at least five people. (1 point)\n",
65 | "2. Write an if test that prints a message about the room being crowded, if there are more than four people in your list. (1 point)\n",
66 | "3. Modify your list so that there are only two people in it. Use one of the methods for removing people from the list, don't just redefine the list. (2 points)\n",
67 | "4. Add some names to your list, so that there are at least seven people in the list. Use one of the methods for appending people from the list, don't just redefine the list. (1 point)"
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": null,
73 | "metadata": {
74 | "id": "t4SnJYWHYc1a"
75 | },
76 | "outputs": [],
77 | "source": []
78 | },
79 | {
80 | "cell_type": "markdown",
81 | "metadata": {
82 | "id": "72ZcTAGWYc1b"
83 | },
84 | "source": [
85 | "## Ex 3\n",
86 | "This exercise covers variables, lists, and if-statements (total: 4 points)"
87 | ]
88 | },
89 | {
90 | "cell_type": "markdown",
91 | "metadata": {
92 | "id": "-7-5-5waYc1b"
93 | },
94 | "source": [
95 | "1. Create a list of lists where each sub list holds the arguments for the function. Loop this list of lists and first check if the length of inner list is not 2, then print an error message \"Length of numbers must be 2!\" and continue to the next iteration (use the `continue` statement). Otherwise call the function and print the result of the function. (2 points)\n",
96 | "\n",
97 | "2. Test your code by this list of lists: `number_lists = [[1, 1], [\"five\", 3], [5, \"three\"], [2, 2, 2], [5.5, 8]]` (1 point)\n",
98 | "\n",
99 | "3. Replace `continue` statement with `break` statement and run your code again. Could you notice the difference? (1 point)"
100 | ]
101 | },
102 | {
103 | "cell_type": "code",
104 | "execution_count": null,
105 | "metadata": {
106 | "id": "BRivZfxYYc1b"
107 | },
108 | "outputs": [],
109 | "source": []
110 | }
111 | ],
112 | "metadata": {
113 | "colab": {
114 | "provenance": []
115 | },
116 | "kernelspec": {
117 | "display_name": "Python 3 (ipykernel)",
118 | "language": "python",
119 | "name": "python3"
120 | },
121 | "language_info": {
122 | "codemirror_mode": {
123 | "name": "ipython",
124 | "version": 3
125 | },
126 | "file_extension": ".py",
127 | "mimetype": "text/x-python",
128 | "name": "python",
129 | "nbconvert_exporter": "python",
130 | "pygments_lexer": "ipython3",
131 | "version": "3.11.5"
132 | },
133 | "toc": {
134 | "base_numbering": 1,
135 | "nav_menu": {},
136 | "number_sections": false,
137 | "sideBar": false,
138 | "skip_h1_title": true,
139 | "title_cell": "Table of Contents",
140 | "title_sidebar": "Contents",
141 | "toc_cell": false,
142 | "toc_position": {},
143 | "toc_section_display": false,
144 | "toc_window_display": false
145 | }
146 | },
147 | "nbformat": 4,
148 | "nbformat_minor": 1
149 | }
150 |
--------------------------------------------------------------------------------
/SEDS_23/day 1_ Monday/notebooks/11_var_string_num_ex1_1.py:
--------------------------------------------------------------------------------
1 | # Store a message in a variable
2 | msg = "Hey"
3 | # Print that message
4 | print(msg)
5 |
6 | # Store a new message in the same variable
7 | msg = "How are you?"
8 | # Print that new message
9 | print(msg)
--------------------------------------------------------------------------------
/SEDS_23/day 1_ Monday/notebooks/11_var_string_num_ex1_2.py:
--------------------------------------------------------------------------------
1 | print("####### Part 1:")
2 | # Store the quote in a variable.
3 | quote = "One of my most productive days was throwing away 1000 lines of code"
4 | # Store the full name of the person in another variable.
5 | person = "Ken Thompson"
6 |
7 | # Print a sentence in such format "X once said, 'quote comes here'."
8 | sentence = "{} once said, '{}'.".format(person, quote)
9 | print(sentence)
10 |
11 | print("####### Part 2:")
12 | # Store a first name and a last name, in lowercase, in 2 different variables.
13 | first_name = "name"
14 | last_name = "surname"
15 | # Using that variables store the full name in another variable (concatenation)
16 | full_name = first_name + " " + last_name
17 | # full_name = "{} {}".format(first_name, last_name)
18 |
19 | # Print the full name in lowercase, Titlecase, and UPPERCASE.
20 | print(full_name)
21 | print(full_name.lower())
22 | print(full_name.title())
23 | print(full_name.upper())
--------------------------------------------------------------------------------
/SEDS_23/day 1_ Monday/notebooks/12_lists_tuples-1_ex1_1.py:
--------------------------------------------------------------------------------
1 | #Exercises
2 | """
3 |
4 | First Neat List
5 |
6 | Store the values 'python', 'c', and 'java' in a list. Print a statement about each of these values,
7 | using their position in the list.
8 | Your statement could simply be, 'A nice programming language is value.'
9 |
10 | """
11 |
12 |
13 | languages = ['python', 'c', 'java']
14 |
15 | print("A nice programming language is " + languages[0])
16 | print("A nice programming language is " + languages[1])
17 | print("A nice programming language is {}".format(languages[2]))
18 |
19 |
20 | print("\n")
21 |
22 |
23 | """
24 |
25 | Your First List
26 |
27 | Think of something you can store in a list. Make a list with three or four items,
28 | and then print a message that includes at least one item from your list.
29 | Your sentence could be as simple as, "One item in my list is a ____."
30 |
31 | """
32 |
33 | my_list = [3, 'my CD', 'Kessler', 2.5]
34 |
35 | print("The thing that I cannot live without is {}.".format(my_list[1]))
36 |
--------------------------------------------------------------------------------
/SEDS_23/day 1_ Monday/notebooks/12_lists_tuples-1_ex1_2.py:
--------------------------------------------------------------------------------
1 | #Exercises
2 | """
3 |
4 | First Neat List - Loop
5 |
6 | Repeat First Neat List, but this time use a loop to print out your statements.
7 | Make sure you are writing the same sentence for all values in your list.
8 | Loops are not effective when you are trying to generate different output for each value in your list.
9 |
10 | """
11 | languages = ['python', 'c', 'java']
12 |
13 |
14 | for language in languages:
15 | print("A nice programming language is " + language)
16 |
17 |
18 | print("\n")
19 |
20 |
21 |
22 | """
23 |
24 | Your First List - Loop
25 |
26 | Repeat Your First List, but this time use a loop to print out your message for each item in your list.
27 | Again, if you came up with different messages for each value in your list, decide on one message to
28 | repeat for each value in your list.
29 |
30 | """
31 |
32 | my_list = [3, 'my CD', 'Kessler', 2.5]
33 |
34 | for thing in my_list:
35 | print("The thing that I cannot live without is {}.".format(thing))
36 |
37 |
--------------------------------------------------------------------------------
/SEDS_23/day 1_ Monday/notebooks/13_if_statements_ex1_1.py:
--------------------------------------------------------------------------------
1 | print("####### Gymnast Scores - 2")
2 | scores = range(1, 11)
3 |
4 | for score in scores:
5 | # if score != 1:
6 | # if score >= 2:
7 | if score > 1:
8 | print("A judge can give a gymnast {} points.".format(score))
9 | else:
10 | print("A judge can give a gymnast {} point.".format(score))
11 |
12 | print("\n####### Numbers")
13 | saved_numbers = [2, 1, 5, 12, 42, 34, 52]
14 | new_numbers = [3, 1, 33, 52, 4]
15 |
16 | for new_number in new_numbers:
17 | if new_number not in saved_numbers:
18 | saved_numbers.append(new_number)
19 | print("{} is now saved".format(new_number))
20 | else:
21 | print("{} is already saved".format(new_number))
--------------------------------------------------------------------------------
/SEDS_23/day 1_ Monday/notebooks/13_if_statements_ex1_2.py:
--------------------------------------------------------------------------------
1 | # Make a list of ten aliens, each of which is one color: 'red', 'green', or 'blue'.
2 | aliens = ["red", "green", "pink", "blue", "red", "blue", "green", "red", "red", "blue"]
3 | print("number of aliens:", len(aliens))
4 |
5 | # Use a for loop to determine the number of points a player would earn for destroying all of the aliens in your list
6 | current_score = 0
7 | for alien_color in aliens:
8 | if alien_color == "red":
9 | current_score = current_score + 5
10 | elif alien_color == "green":
11 | current_score = current_score + 10
12 | elif alien_color == "blue":
13 | current_score = current_score + 20
14 | else:
15 | print("I don't know points of color '{}'".format(alien_color))
16 | print("total points: {}".format(current_score))
--------------------------------------------------------------------------------
/SEDS_23/day 2_Tuesday/assignment/ex_2.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "SN-mb9j3Yc1X"
7 | },
8 | "source": [
9 | "# Assignment 2: Python basics and programming fundamentals\n",
10 | "Indira Sen, Claire Jordan, Elena Solar, Andri Rutschmann\n",
11 | "\n",
12 | "Winter Term 2023 / 2024\n",
13 | "\n",
14 | "In this first assignment we will practice how to use more advanced data structure like dictionaries as well more intricate programming concepts such as functions. You can score up to 15 points in this assignment. Please submit your solutions inside this notebook in your repository on GitHub. Be sure to add your name, email and matriculation number. The deadline for submission is on Tuesday, October 17, 23:00 hours. You will get individual feedback in your repository."
15 | ]
16 | },
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {
20 | "id": "72ZcTAGWYc1b"
21 | },
22 | "source": [
23 | "## Ex 1 (Total: 4 points)\n",
24 | "This exercise covers variables, lists, and if-statements. You will repeat the first exercise of the first assignment but this time with functions."
25 | ]
26 | },
27 | {
28 | "cell_type": "markdown",
29 | "metadata": {
30 | "id": "-7-5-5waYc1b"
31 | },
32 | "source": [
33 | "Note: Please try to utilize functions during this exercise (instead of repeating tests!).\n",
34 | "\n",
35 | "A. Make a list of names that includes at least four people. (0.5 points)\n",
36 | "\n",
37 | "B. Write an if test that prints a message about the room being crowded, if there are more than three people in your list. (0.5 points)\n",
38 | "\n",
39 | "C. Modify your list so that there are only two people in it. Use one of the methods for removing people from the list, don't just redefine the list. (0.5 points)\n",
40 | "\n",
41 | "D. Run your if test again. There should be no output this time, because there are less than three people in the list. (1 point)\n",
42 | "\n",
43 | "E. Add an `else` statement to your if tests. If the `else` statement is run, have it print a message that the room is not very crowded. (0.5 point)\n",
44 | "\n",
45 | "F. Add some names to your list, so that there are at least six people in the list. Use one of the methods for appending people from the list, don't just redefine the list. (0.5 point)\n",
46 | "\n",
47 | "G. Modify your tests so that\n",
48 | " - If there are more than 5 people, a message is printed about the room being very crowded.\n",
49 | " - If there are 3-5 people, a message is printed about the room being crowded.\n",
50 | " - If there are 1 or 2 people, a message is printed about the room not being crowded.\n",
51 | " - If there are no people in the room, a message is printed abou the room being empty.\n",
52 | " (0.5 points)"
53 | ]
54 | },
55 | {
56 | "cell_type": "code",
57 | "execution_count": null,
58 | "metadata": {
59 | "id": "BRivZfxYYc1b"
60 | },
61 | "outputs": [],
62 | "source": []
63 | },
64 | {
65 | "cell_type": "markdown",
66 | "metadata": {
67 | "id": "K8UhXKdwYc1b"
68 | },
69 | "source": [
70 | "## Ex 2 (Total: 5.5 points)"
71 | ]
72 | },
73 | {
74 | "cell_type": "markdown",
75 | "metadata": {
76 | "id": "vCY9U6Q2Yc1b"
77 | },
78 | "source": [
79 | "\n",
80 | "#### Mountain Heights 2\n",
81 | "- This is an extension of [Mountain Heights](#exercise_mountain_heights). Make sure you save this program under a different filename, such as *mountain\\_heights_3.py*, so that you can go back to your original program if you need to.\n",
82 | "\n",
83 | "A. The list of [tallest mountains in the world](http://en.wikipedia.org/wiki/List_of_mountains_by_elevation) provided all elevations in meters. Convert each of these elevations to feet, given that a meter is approximately 3.28 feet. You can do these calculations by hand at this point. (1 point)\n",
84 | "\n",
85 | "B. Create a new dictionary, where the keys of the dictionary are still the mountains' names. This time however, the values of the dictionary should be a list of each mountain's elevation in meters, and then in feet: {'everest': [8848, 29029]} (1 point)\n",
86 | "\n",
87 | "C. Print out just the mountains' names, by looping through the keys of your dictionary. (0.5 points)\n",
88 | "\n",
89 | "D. Print out just the mountains' elevations in meters, by looping through the values of your dictionary and pulling out the first number from each list. (0.5 points)\n",
90 | "\n",
91 | "E. Print out just the mountains' elevations in feet, by looping through the values of your dictionary and pulling out the second number from each list. (0.5 points)\n",
92 | "\n",
93 | "F. Print out a series of statements telling how tall each mountain is: \"Everest is 8848 meters tall, or 29029 feet.\" (1 point)\n",
94 | "\n",
95 | "G. Bonus: Start with your original program from [Mountain Heights](#exercise_mountain_heights). Write a function that reads through the elevations in meters, and returns a list of elevations in feet. Use this list to create the nested dictionary described above. (1 point)"
96 | ]
97 | },
98 | {
99 | "cell_type": "code",
100 | "execution_count": null,
101 | "metadata": {
102 | "id": "ubkwD2i09qKN"
103 | },
104 | "outputs": [],
105 | "source": []
106 | },
107 | {
108 | "cell_type": "markdown",
109 | "metadata": {
110 | "id": "drk1BMvSYc1c"
111 | },
112 | "source": [
113 | "## Ex 3 (Total: 5.5 points)"
114 | ]
115 | },
116 | {
117 | "cell_type": "markdown",
118 | "metadata": {
119 | "id": "u8IfFneKYc1c"
120 | },
121 | "source": [
122 | "#### Mountain Heights 2\n",
123 | "- This is one more extension of Mountain Heights.\n",
124 | "\n",
125 | "A. Create a new dictionary, where the keys of the dictionary are once again the mountains' names. This time, the values of the dictionary are another dictionary. This dictionary should contain the elevation in either meters or feet, and the range that contains the mountain. For example: {'everest': {'elevation': 8848, 'range': 'himalaya'}}. (2 points)\n",
126 | "\n",
127 | "B. Print out just the mountains' names. (0.5 points)\n",
128 | "\n",
129 | "C. Print out just the mountains' elevations. (0.5 points)\n",
130 | "\n",
131 | "D. Print out just the range for each mountain. (0.5 points)\n",
132 | "\n",
133 | "E. Print out a series of statements that say everything you know about each mountain: \"Everest is an 8848-meter tall mountain in the Himalaya range.\" (2 points)"
134 | ]
135 | },
136 | {
137 | "cell_type": "code",
138 | "execution_count": null,
139 | "metadata": {
140 | "id": "wPiWEzm1Yc1c"
141 | },
142 | "outputs": [],
143 | "source": []
144 | }
145 | ],
146 | "metadata": {
147 | "colab": {
148 | "provenance": []
149 | },
150 | "kernelspec": {
151 | "display_name": "Python 3 (ipykernel)",
152 | "language": "python",
153 | "name": "python3"
154 | },
155 | "language_info": {
156 | "codemirror_mode": {
157 | "name": "ipython",
158 | "version": 3
159 | },
160 | "file_extension": ".py",
161 | "mimetype": "text/x-python",
162 | "name": "python",
163 | "nbconvert_exporter": "python",
164 | "pygments_lexer": "ipython3",
165 | "version": "3.11.5"
166 | },
167 | "toc": {
168 | "base_numbering": 1,
169 | "nav_menu": {},
170 | "number_sections": false,
171 | "sideBar": false,
172 | "skip_h1_title": true,
173 | "title_cell": "Table of Contents",
174 | "title_sidebar": "Contents",
175 | "toc_cell": false,
176 | "toc_position": {},
177 | "toc_section_display": false,
178 | "toc_window_display": false
179 | }
180 | },
181 | "nbformat": 4,
182 | "nbformat_minor": 1
183 | }
184 |
--------------------------------------------------------------------------------
/SEDS_23/day 2_Tuesday/notebooks/21_lists_tuples-2_ex1_1.py:
--------------------------------------------------------------------------------
1 | """
2 | Working List
3 |
4 | Make a list that includes four careers, such as 'programmer' and 'truck driver'.
5 | """
6 | print("Part 1")
7 | careers = ['doctor', 'scientist', 'historian', 'teacher']
8 |
9 | print("\nUse the list.index() function to find the index of one career in your list.")
10 |
11 | print(careers.index('historian'))
12 |
13 | print("\nUse the in function to show that this career is in your list.")
14 |
15 | print('historian' in careers)
16 |
17 | print("\nUse the append() function to add a new career to your list.")
18 |
19 | careers.append('politician')
20 | print(careers)
21 |
22 | print("\nUse the insert() function to add a new career at the beginning of the list.")
23 |
24 | careers.insert(0, 'archeologist')
25 | print(careers)
26 | print("\n")
27 |
28 | """
29 | Ordered Working List
30 | """
31 |
32 | print("Start with the list you created in Working List.")
33 |
34 |
35 |
36 | print("\nYou are going to print out the list in a number of different orders.")
37 | print("Each time you print the list, use a for loop rather than printing the raw list.")
38 | print("Print a message each time telling us what order we should see the list in.")
39 |
40 | print("\nPrint the list in its original order.")
41 |
42 | for career in careers:
43 | print(career)
44 |
45 | print("\nPrint the list in alphabetical order.")
46 |
47 | for career in sorted(careers):
48 | print(career)
49 |
50 | print("\nPrint the list in reverse alphabetical order.")
51 |
52 | for career in sorted(careers, reverse = True):
53 | print(career)
54 |
55 | print("\nPermanently sort the list in alphabetical order, and then print it out.")
56 |
57 | careers.sort()
58 |
59 | for career in careers:
60 | print(career)
61 |
62 |
63 | print("\n")
64 | """
65 | List Lengths
66 | """
67 |
68 | print("Copy two or three of the lists you made from the previous exercises, or make up two or three new lists.")
69 |
70 | languages = ['python', 'c', 'java']
71 |
72 | print("\nPrint out a series of statements that tell us how long each list is.")
73 |
74 | print("the new_careers list is {} items long.".format(len(careers)))
75 | print("the languages list is {} items long.".format(len(languages)))
--------------------------------------------------------------------------------
/SEDS_23/day 2_Tuesday/notebooks/21_lists_tuples-2_ex1_2.py:
--------------------------------------------------------------------------------
1 | print("Gymnast Scores")
2 |
3 | print("Store the possible scores a gymnast can earn from one judge in a list.")
4 |
5 | scores = []
6 | for score in range(1,11):
7 | scores.append(score)
8 |
9 | print("\nPrint out the sentence, \"The lowest possible score is ___, and the highest possible score is ___.\" Use the values from your list.")
10 |
11 | print("The lowest possible score is {0}, and the highest possible score is {1}.".format(scores[0], scores[-1]))
12 |
13 |
14 | print("\nPrint out a series of sentences, \"A judge can give a gymnast ___ points.\"")
15 | print("\nDon't worry if your first sentence reads \"A judge can give a gymnast 1 points.")
16 |
17 | for score in scores:
18 | print("A judge can give a gymnast {} points.".format(score))
19 |
20 |
21 | print("\nHowever, you get 1000 bonus internet points if you can use a for loop, and have correct grammar.")
22 |
23 | print("A judge can give a gymnast {} point.".format(scores[0]))
24 | for score in scores[1:]:
25 | print("A judge can give a gymnast {} points.".format(score))
26 |
27 | print("\nPop the first five elements (by position) and remove the last(by value).")
28 | for score in range(1,5):
29 | scores.pop(0)
30 |
31 | print(scores)
32 |
33 | scores.remove(10)
34 |
35 | print(scores)
--------------------------------------------------------------------------------
/SEDS_23/day 2_Tuesday/notebooks/21_lists_tuples-2_ex1_3.py:
--------------------------------------------------------------------------------
1 | print("First Twenty")
2 |
3 | print("Use the range() function to store the first twenty numbers (1-20) in a list, and print them out.")
4 |
5 | first_twenty = range(1,21)
6 |
7 | for number in first_twenty:
8 | print(number)
9 |
10 | print("\nFive Wallets")
11 |
12 | print("Imagine five wallets with different amounts of cash in them. Store these five values in a list")
13 |
14 | wallets = [2000, 12, 456, 9, 10000]
15 |
16 | print("The fattest wallet has {} in it.".format(sorted(wallets, reverse = True)[0]))
17 | print("The skinniest wallet has {} in it.".format(sorted(wallets)[0]))
18 | print("All together, these wallets have $ {} in them.".format(sum(wallets)))
--------------------------------------------------------------------------------
/SEDS_23/day 2_Tuesday/notebooks/22_dictionaries_ex1_1.py:
--------------------------------------------------------------------------------
1 | #Pet Names
2 |
3 | # Create a dictionary to hold information about pets. Each key is an animal's name, and each value is the kind of animal.
4 | # For example, 'ziggy': 'canary'
5 | # Put at least 3 key-value pairs in your dictionary.
6 |
7 |
8 | pets = {'Tom': 'cat', 'Spike' : 'dog', 'Jerry' : 'mouse', 'Remi' : 'rat'}
9 | print(pets)
10 |
11 | # Modify one of the values in your dictionary. You could clarify to name a breed, or you could change an animal from a cat to a dog.
12 |
13 | pets['Tom'] = 'stray cat'
14 |
15 | # Add a new key-value pair to your dictionary.
16 |
17 | pets['Toothless' : 'dragon']
--------------------------------------------------------------------------------
/SEDS_23/day 2_Tuesday/notebooks/22_dictionaries_ex1_2.py:
--------------------------------------------------------------------------------
1 | # Mountain Heights
2 |
3 | # Wikipedia has a list of the tallest mountains in the world, with each mountain's elevation. Pick five mountains from this list.
4 | print("Create a dictionary with the mountain names as keys, and the elevations as values.")
5 |
6 | mountain_dict = {"Mount Everest": 8448, "K2": 8611, "Kanchenjunga":8586, "Lhotse" : 8516, "Cho Oyu" : 8201}
7 |
8 | print("\n")
9 | print("Print out just the mountains\' names, by looping through the keys of your dictionary.")
10 | for key in mountain_dict.keys():
11 | print(key)
12 |
13 | print("\n")
14 | print("Print out just the mountains' elevations, by looping through the values of your dictionary.")
15 | for val in mountain_dict.values():
16 | print(val)
17 |
18 | print("\n")
19 | print("Print out a series of statements telling how tall each mountain is: \"Everest is 8848 meters tall.\"")
20 | for key, val in mountain_dict.items():
21 | print("%s is %d meters tall." %(key,val))
--------------------------------------------------------------------------------
/SEDS_23/day 2_Tuesday/notebooks/23_functions_ex1_1.py:
--------------------------------------------------------------------------------
1 | def greet(first_name, last_name):
2 | # print("Hello {} {}".format(first_name, last_name))
3 | # print("I wish you a very nice day.")
4 |
5 | print("Hello {} {},\nI wish you a very nice day.\n".format(first_name, last_name))
6 |
7 | people = [["Adriana", "Schmidt"], ["Billy", "Müller"], ["Caroline", "Schneider"]]
8 | for first_name, last_name in people:
9 | greet(first_name, last_name)
10 |
11 | # for person_data in people:
12 | # greet(person_data[0], person_data[1])
--------------------------------------------------------------------------------
/SEDS_23/day 3_Wednesday/assignment/customers.csv:
--------------------------------------------------------------------------------
1 | ,cust_id,first_name_,last_name_,price_count,price_sum,price_mean
2 | 0,1,Max, Mustemann,4,155.96,38.99
3 | 1,2,Ben, Mayer,3,68.97,22.99
4 | 2,3,Sarah, Mueller,4,177.96,44.49
5 | 3,4,Tina, Berger,8,226.92,28.36
6 | 4,5,Donald, T.,9,381.91,42.43
7 | 5,6,Miriam, Faber,2,45.98,22.99
8 | 6,8,Fabian, Engelbert,1,15.99,15.99
9 | 7,9,Hans, Kleber,7,245.93,35.13
10 | 8,10,Brigitte, Jefferson,2,31.98,15.99
11 |
--------------------------------------------------------------------------------
/SEDS_23/day 3_Wednesday/assignment/ex_3.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "bGIGSnHXLvId"
7 | },
8 | "source": [
9 | "# Assignment 3: Loops, Functions, and Data Exploration with Pandas\n",
10 | "\n",
11 | "Indira Sen, Claire Jordan, Elena Solar, Andri Rutschmann\n",
12 | "\n",
13 | "Winter Term 2023 / 2024\n",
14 | "\n",
15 | "You can score up to 15 points in this assignment. Please submit your solutions inside this notebook in your repository on GitHub. The deadline for submission is on Wednesday, October 18, 23:00 hours. You will get individual feedback in your repository."
16 | ]
17 | },
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {
21 | "id": "0tfnt0QN-98D"
22 | },
23 | "source": [
24 | "# Ex 1: Quality of Government Dataset (Total: 4.5 points)\n",
25 | "Read in the government dataset directly from \"http://www.qogdata.pol.gu.se/data/qog_std_cs_jan19.csv\"\n",
26 | "\n",
27 | "A. How many rows does this dataset have? (0.5 points)\n",
28 | "\n",
29 | "B. How many columns does this dataset have? (0.5 points)\n",
30 | "\n",
31 | "C. Select the following columns from the dataset:\n",
32 | "\"cname\", \"wdi_pop\", \"wdi_popgr\", \"wdi_gdpcapcur\", \"wdi_gdpcapgr\", \"wdi_area\", \"wdi_broadb\", \"ht_region\" into another dataframe (0.5 points)\n",
33 | "\n",
34 | "D. Rename the columns to: \"country\", \"population\",\"population_growth\", \"gdp_per_capita\", \"gdp_growth\", \"area\", \"internet\", \"region\" (0.5 points)\n",
35 | "\n",
36 | "E. Rename the region codes 1-10 with\n",
37 | "\"Eastern Europe\", \"Latin America\", \"North Africa & Middle East\", \"Sub-Saharan Africa\", \"Western Europe and North America\", \"East Asia\",\"South-East Asia\", \"South Asia\", \"Pacific\", \"Caribbean\" (1 point)\n",
38 | "\n",
39 | "F. What are the mean values for each attribute? (1 point)\n",
40 | "\n",
41 | "G. Which country has the highest population in the region \"Eastern Europe\"? (0.5 points)"
42 | ]
43 | },
44 | {
45 | "cell_type": "code",
46 | "execution_count": null,
47 | "metadata": {
48 | "id": "yhJWcviy-98G"
49 | },
50 | "outputs": [],
51 | "source": []
52 | },
53 | {
54 | "cell_type": "markdown",
55 | "metadata": {
56 | "id": "Svgbispj-98J"
57 | },
58 | "source": [
59 | "# Ex 2: Book and Movie shop (Total: 5 points)"
60 | ]
61 | },
62 | {
63 | "cell_type": "markdown",
64 | "metadata": {
65 | "id": "ZPpYj_nt-98K"
66 | },
67 | "source": [
68 | "For a virtual shop that sells movies and books, we have four tables:\n",
69 | " \n",
70 | " 1. pd_customers: Gives first- and lastname for each customer\n",
71 | " 2. pd_books: Gives the raw price for all books that are being sold\n",
72 | " 3. pd_movies: Gives the raw price for all movies that are being sold\n",
73 | " 4. pd_transactions: Gives the list of all transactions being made (which customer bought which item)\n",
74 | "\n",
75 | "Do the following:\n",
76 | "\n",
77 | "A. Load all 4 datasets in separate dataframes (2 points)\n",
78 | "\n",
79 | "B. Compile a listing of all items (=books and movies) that have been sold in one dataframe\n",
80 | "The dataframe should contain two columns: \"item_name\" and \"price\" (1 point)\n",
81 | "\n",
82 | "C. Compute lists of the top 10 bestselling items, both by count and by sum of prices (2 points)"
83 | ]
84 | },
85 | {
86 | "cell_type": "code",
87 | "execution_count": null,
88 | "metadata": {
89 | "id": "AOr8rbkk-98K"
90 | },
91 | "outputs": [],
92 | "source": []
93 | },
94 | {
95 | "cell_type": "markdown",
96 | "metadata": {},
97 | "source": [
98 | "# Ex 3: Revisiting Adults.csv (Total: 5.5 points)"
99 | ]
100 | },
101 | {
102 | "cell_type": "markdown",
103 | "metadata": {},
104 | "source": [
105 | "A. Use adult_df from the morning session (0.5 points)\n",
106 | "\n",
107 | "B. Get all persons with a Bachelor degree as their highest degree into 'bachelors' dataframe (1 point)\n",
108 | "\n",
109 | "C. Print the number of those persons (0.5 points)\n",
110 | "\n",
111 | "D. Print the sum of their capital_gain (1 point)\n",
112 | "\n",
113 | "E. Sort them according to their capital_gain and age in descending order and save in the same object (0.5 points)\n",
114 | "\n",
115 | "F. Print first 10 of those persons who has age between 20 and 40 (0.5 points)\n",
116 | "\n",
117 | "G. Print the correlation between age and capital gain based on different educations levels. Write a 2-sentence takeaway on your findings (1.5 points)"
118 | ]
119 | },
120 | {
121 | "cell_type": "code",
122 | "execution_count": null,
123 | "metadata": {},
124 | "outputs": [],
125 | "source": []
126 | }
127 | ],
128 | "metadata": {
129 | "colab": {
130 | "provenance": []
131 | },
132 | "hide_input": false,
133 | "kernelspec": {
134 | "display_name": "Python 3 (ipykernel)",
135 | "language": "python",
136 | "name": "python3"
137 | },
138 | "language_info": {
139 | "codemirror_mode": {
140 | "name": "ipython",
141 | "version": 3
142 | },
143 | "file_extension": ".py",
144 | "mimetype": "text/x-python",
145 | "name": "python",
146 | "nbconvert_exporter": "python",
147 | "pygments_lexer": "ipython3",
148 | "version": "3.11.5"
149 | },
150 | "nav_menu": {},
151 | "toc": {
152 | "base_numbering": 1,
153 | "nav_menu": {},
154 | "number_sections": true,
155 | "sideBar": true,
156 | "skip_h1_title": false,
157 | "title_cell": "Table of Contents",
158 | "title_sidebar": "Contents",
159 | "toc_cell": false,
160 | "toc_position": {},
161 | "toc_section_display": false,
162 | "toc_window_display": false
163 | },
164 | "varInspector": {
165 | "cols": {
166 | "lenName": 16,
167 | "lenType": 16,
168 | "lenVar": 40
169 | },
170 | "kernels_config": {
171 | "python": {
172 | "delete_cmd_postfix": "",
173 | "delete_cmd_prefix": "del ",
174 | "library": "var_list.py",
175 | "varRefreshCmd": "print(var_dic_list())"
176 | },
177 | "r": {
178 | "delete_cmd_postfix": ") ",
179 | "delete_cmd_prefix": "rm(",
180 | "library": "var_list.r",
181 | "varRefreshCmd": "cat(var_dic_list()) "
182 | }
183 | },
184 | "types_to_exclude": [
185 | "module",
186 | "function",
187 | "builtin_function_or_method",
188 | "instance",
189 | "_Feature"
190 | ],
191 | "window_display": false
192 | }
193 | },
194 | "nbformat": 4,
195 | "nbformat_minor": 1
196 | }
197 |
--------------------------------------------------------------------------------
/SEDS_23/day 3_Wednesday/assignment/pd_books.csv:
--------------------------------------------------------------------------------
1 | book,price
2 | Book 1,9.99
3 | Book 2,8.99
4 | Book 3,29.99
5 | Book 4,8.49
6 | Book 5,15.99
7 | Book 6,12.19
8 | Book 7,13.99
9 | Book 8,49.99
10 | Book 9,125.99
11 | Book 10,8.99
12 |
--------------------------------------------------------------------------------
/SEDS_23/day 3_Wednesday/assignment/pd_customers.csv:
--------------------------------------------------------------------------------
1 | cust_id,first_name,last_name
2 | 1,Max, Mustemann
3 | 2,Ben, Mayer
4 | 3,Sarah, Mueller
5 | 4,Tina, Berger
6 | 5,Donald, T.
7 | 6,Miriam, Faber
8 | 7,Thomas, Hase
9 | 8,Fabian, Engelbert
10 | 9,Hans, Kleber
11 | 10,Brigitte, Jefferson
12 |
--------------------------------------------------------------------------------
/SEDS_23/day 3_Wednesday/assignment/pd_movies.csv:
--------------------------------------------------------------------------------
1 | movie,price
2 | Movie 1,15.99
3 | Movie 2,22.99
4 | Movie 3,15.99
5 | Movie 4,14.49
6 | Movie 5,3.99
7 | Movie 6,2.19
8 | Movie 7,11.99
9 | Movie 8,31.99
10 | Movie 9,35.99
11 | Movie 10,1.99
12 |
--------------------------------------------------------------------------------
/SEDS_23/day 3_Wednesday/assignment/pd_transactions.csv:
--------------------------------------------------------------------------------
1 | cust_id,item
2 | 1,Book 1
3 | 1,Movie 1
4 | 1,Movie 5
5 | 1,Book 9
6 | 2,Book 1
7 | 2,Book 8
8 | 2,Book 10
9 | 3,Movie 1
10 | 3,Movie 5
11 | 3,Movie 8
12 | 3,Book 9
13 | 4,Book 10
14 | 4,Book 7
15 | 4,Movie 8
16 | 4,Movie 3
17 | 4,Book 9
18 | 4,Book 1
19 | 4,Movie 1
20 | 4,Movie 5
21 | 5,Book 9
22 | 5,Book 1
23 | 5,Book 8
24 | 5,Book 10
25 | 5,Movie 1
26 | 5,Movie 5
27 | 5,Movie 8
28 | 5,Book 9
29 | 5,Book 10
30 | 6,Book 7
31 | 6,Movie 8
32 | 8,Movie 3
33 | 9,Book 8
34 | 9,Book 10
35 | 9,Movie 1
36 | 9,Movie 5
37 | 9,Movie 8
38 | 9,Book 9
39 | 9,Book 10
40 | 10,Movie 2
41 | 10,Book 2
--------------------------------------------------------------------------------
/SEDS_23/day 3_Wednesday/notebooks/23_functions_ex1_1.py:
--------------------------------------------------------------------------------
1 | def greet(first_name, last_name):
2 | # print("Hello {} {}".format(first_name, last_name))
3 | # print("I wish you a very nice day.")
4 |
5 | print("Hello {} {},\nI wish you a very nice day.\n".format(first_name, last_name))
6 |
7 | people = [["Adriana", "Schmidt"], ["Billy", "Müller"], ["Caroline", "Schneider"]]
8 | for first_name, last_name in people:
9 | greet(first_name, last_name)
10 |
11 | # for person_data in people:
12 | # greet(person_data[0], person_data[1])
--------------------------------------------------------------------------------
/SEDS_23/day 3_Wednesday/notebooks/23_functions_ex1_2.py:
--------------------------------------------------------------------------------
1 | def calculate_sum(number_1, number_2):
2 | sum_ = number_1 + number_2
3 | return sum_
4 |
5 | number_lists = [[1, 1], [1, 2], [20, 10]]
6 | for n_1, n_2 in number_lists:
7 | output = calculate_sum(n_1, n_2)
8 | print("{} + {} = {}".format(n_1, n_2, output))
--------------------------------------------------------------------------------
/SEDS_23/day 3_Wednesday/notebooks/31_OOP_ex1.py:
--------------------------------------------------------------------------------
1 | class Parrot:
2 | def __init__(self, name, age):
3 | self.name = name
4 | self.age = age
5 | self.words = []
6 |
7 | def add_word(self, word):
8 | self.words.append(word)
9 |
10 | def number_of_words(self):
11 | return len(self.words)
12 |
13 | def describe(self):
14 | print('Name: ', self.name)
15 | print('Age: ', self.age)
16 | print('Words {} can say {}'.format(self.name, ', '.join(self.words)))
17 |
18 | # Example usage:
19 | if __name__ == "__main__":
20 | parrot1 = Parrot("Polly", 5)
21 | parrot1.add_word("Hello")
22 | parrot1.add_word("Goodbye")
23 | parrot1.add_word("Polly wants a cracker")
24 |
25 | print(f"{parrot1.name} can say {parrot1.number_of_words()} words.")
26 | parrot1.describe()
--------------------------------------------------------------------------------
/SEDS_23/day 3_Wednesday/notebooks/32_data_exploration_part_1_ex1_1.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 |
3 | # ####### step 1
4 | adult_df = pd.read_csv("adult.csv", na_values="?")
5 |
6 | # ####### step 2
7 | # get a subset of dataframe
8 | adult_df = adult_df[["age", "sex", "education", "hours-per-week", "capital-gain"]]
9 |
10 | # ####### step 3
11 | # rename a column
12 | adult_df.rename(columns={"capital-gain" : "capital_gain"}, inplace=True)
13 |
14 | print("####### step 4")
15 | print("Column names:", adult_df.columns.values)
16 |
17 | print("####### step 5")
18 | print("Number of different 'education' values:", len(adult_df["education"].unique()))
19 |
20 | print("####### step 6")
21 | print("Mean 'working time per week':", adult_df["hours-per-week"].mean())
22 |
23 | print("####### step 7")
24 | # adult_df["capital_gain"].max()
25 | print("Max capital gain:", adult_df.capital_gain.max())
--------------------------------------------------------------------------------
/SEDS_23/day 3_Wednesday/notebooks/abstraction.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Indiiigo/Intro_to_python/3035764946d2c52d3d86d9e1db7ece284b0f59ee/SEDS_23/day 3_Wednesday/notebooks/abstraction.png
--------------------------------------------------------------------------------
/SEDS_23/day 3_Wednesday/notebooks/inheritance.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Indiiigo/Intro_to_python/3035764946d2c52d3d86d9e1db7ece284b0f59ee/SEDS_23/day 3_Wednesday/notebooks/inheritance.png
--------------------------------------------------------------------------------
/SEDS_23/day 4_Thursday/ex_4.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "0a404715",
6 | "metadata": {
7 | "id": "0a404715"
8 | },
9 | "source": [
10 | "# Assignment 4: Data Collection and Preprocessing\n",
11 | "Indira Sen, Claire Jordan, Elena Solar, Andri Rutschmann\n",
12 | "\n",
13 | "Winter Term 2023 / 2024\n",
14 | "\n",
15 | "In this assignment we will practice how to extract data from the web with Python. You can score up to 15 points in this assignment. Please submit your solutions inside this notebook in your repository on GitHub. The deadline for submission is on Thursday, October 19, 23:59 hours. You will get individual feedback in your repository."
16 | ]
17 | },
18 | {
19 | "cell_type": "markdown",
20 | "id": "Ou_Yq99wDpuH",
21 | "metadata": {
22 | "id": "Ou_Yq99wDpuH"
23 | },
24 | "source": [
25 | "### Exercise 1 (total 6 points)\n",
26 | "\n",
27 | "Explore the Quality of Government Dataset\n",
28 | "\n",
29 | "A. Create a new column \"population_density\" (1 point)\n",
30 | "\n",
31 | "B. How many countries are in each region? (1 point)\n",
32 | "\n",
33 | "C. What is the per country mean population density for each region\n",
34 | "(= sum of densities for each country / number of countries) (0.5 points)\n",
35 | "\n",
36 | "D. Show the population densities for countries in 'Western Europe and North America'\n",
37 | "Obviously, the results are heavily influenced by some outliers. How to avoid that? (1.5 points)\n",
38 | "\n",
39 | "E. What is the actual population density in each region\n",
40 | "(= Sum of population in the region / Sum of areas in the region) (1 points)\n",
41 | "\n",
42 | "Hint: Compute first the population sum and the area sum for each region\n",
43 | "\n",
44 | "F. What countries have the maximum and minimum population growth? (1 point)"
45 | ]
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": null,
50 | "id": "DbCihYnxEqgI",
51 | "metadata": {
52 | "id": "DbCihYnxEqgI"
53 | },
54 | "outputs": [],
55 | "source": []
56 | },
57 | {
58 | "cell_type": "markdown",
59 | "id": "9065912e",
60 | "metadata": {
61 | "id": "9065912e"
62 | },
63 | "source": [
64 | "### Exercise 2 (total: 5 points)\n",
65 | "\n",
66 | "Revisiting the Book and Movie shop. You may reuse the codeyou wrote yesterday. \n",
67 | "\n",
68 | "Recall our virtual shop that sells movies and books, where we have four tables: \n",
69 | "* pd_customers: Gives first- and lastname for each customer \n",
70 | "* pd_books: Gives the raw price for all books that are being sold \n",
71 | "* pd_movies: Gives the raw price for all movies that are being sold \n",
72 | "* pd_transactions: Gives the list of all transactions being made (which customer bought which item)\n",
73 | "\n",
74 | "A. Reload all 4 datasets in separate dataframes (0.5 points)\n",
75 | "\n",
76 | "\n",
77 | "B. Compile a listing of all items (=books and movies) that have been sold in one dataframe. The dataframe should contain two columns: \"item_name\" and \"price\" (0.5 points)\n",
78 | "\n",
79 | "\n",
80 | "C. Join the information on customer names, transactions, and prices in one dataframe (1 point)\n",
81 | "\n",
82 | "\n",
83 | "D. Compute a table of customers. For all customers give the number of items bought, the sum of these items, and the average price of the item. (1 point)\n",
84 | "\n",
85 | "\n",
86 | "E. Extend that list such that it also contains customers without purchases (1 point)\n",
87 | "\n",
88 | "\n",
89 | "F. Round the price mean and the price sum to two digits and export the table to a .csv file (1 point)"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "id": "N2Gh5KSJCx1f",
96 | "metadata": {
97 | "id": "N2Gh5KSJCx1f"
98 | },
99 | "outputs": [],
100 | "source": []
101 | },
102 | {
103 | "cell_type": "markdown",
104 | "id": "bf0e28d8",
105 | "metadata": {
106 | "id": "bf0e28d8"
107 | },
108 | "source": [
109 | "### Exercise 3 (total: 4 points)\n",
110 | "Let's scrape more content"
111 | ]
112 | },
113 | {
114 | "cell_type": "markdown",
115 | "id": "7b01a72b",
116 | "metadata": {
117 | "id": "7b01a72b"
118 | },
119 | "source": [
120 | "A. Reuse the list of users (). Write a function to extract the gender of users per userbox info. Don't run it on the whole dataframe, just make sure it works with several examples. (2 points)\n",
121 | " \n",
122 | "B. Go to the start page of 'waz.de' and get all the news story titles you can. (2 points)"
123 | ]
124 | },
125 | {
126 | "cell_type": "code",
127 | "execution_count": null,
128 | "id": "KC4cWWZbC3AT",
129 | "metadata": {
130 | "id": "KC4cWWZbC3AT"
131 | },
132 | "outputs": [],
133 | "source": []
134 | }
135 | ],
136 | "metadata": {
137 | "colab": {
138 | "provenance": []
139 | },
140 | "kernelspec": {
141 | "display_name": "Python 3 (ipykernel)",
142 | "language": "python",
143 | "name": "python3"
144 | },
145 | "language_info": {
146 | "codemirror_mode": {
147 | "name": "ipython",
148 | "version": 3
149 | },
150 | "file_extension": ".py",
151 | "mimetype": "text/x-python",
152 | "name": "python",
153 | "nbconvert_exporter": "python",
154 | "pygments_lexer": "ipython3",
155 | "version": "3.11.5"
156 | },
157 | "vscode": {
158 | "interpreter": {
159 | "hash": "8a31fc8654382fa70e01b8b1b084ed875bc80468ef06668984d01fe98600013e"
160 | }
161 | }
162 | },
163 | "nbformat": 4,
164 | "nbformat_minor": 5
165 | }
166 |
--------------------------------------------------------------------------------
/SEDS_23/day 4_Thursday/notebooks/41_data_preprocessing_ex1.py:
--------------------------------------------------------------------------------
1 | print("A Use Census data")
2 |
3 |
4 | df = pd.read_csv ("data/adult.csv", na_values="?")
5 | df.head()
6 |
7 | print("A. Show for each combination of sex and race, how many instances(people) are contained in the dataset")
8 |
9 |
10 | df.groupby(["sex", "race"]).size().unstack()
11 |
12 | print("B. What is the mean age of men and women in this dataset?")
13 |
14 |
15 | g = df[['sex', 'age']].groupby("sex")
16 | g.mean()["age"]
17 |
18 | print("C. Show for each combination of marital-Status and race how many males/females over 40 years have a bachelor degree as their highest degree?")
19 |
20 |
21 | df2 = df[(df["age"] > 40) & (df["education"] =="Bachelors")]
22 | df2.groupby(["marital-status","race","sex"]).size().unstack().fillna(0)
--------------------------------------------------------------------------------
/SEDS_23/day 4_Thursday/notebooks/data/weather.csv:
--------------------------------------------------------------------------------
1 | time,temperature,status
2 | 2017-08-31 11:00:00,15,rainy
3 | 2017-08-31 23:00:00,8,rainy
4 | 2017-09-01 11:00:00,19,rainy
5 | 2017-09-01 23:00:00,9,rainy
6 | 2017-09-02 11:00:00,21,cloudy
7 | 2017-09-03 11:00:00,21,cloudy
8 | 2017-09-04 11:00:00,22,sunny
9 | 2017-09-04 23:00:00,12,sunny
10 | 2017-09-05 11:00:00,24,sunny
11 | 2017-09-05 23:00:00,13,sunny
--------------------------------------------------------------------------------
/SEDS_23/day 4_Thursday/notebooks/data/wiki_users.p:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Indiiigo/Intro_to_python/3035764946d2c52d3d86d9e1db7ece284b0f59ee/SEDS_23/day 4_Thursday/notebooks/data/wiki_users.p
--------------------------------------------------------------------------------
/SEDS_23/day 4_Thursday/notebooks/my_df.p:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Indiiigo/Intro_to_python/3035764946d2c52d3d86d9e1db7ece284b0f59ee/SEDS_23/day 4_Thursday/notebooks/my_df.p
--------------------------------------------------------------------------------
/SEDS_23/day 5_Friday/assignment/ex_5.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "VDM62QDIgOyE"
7 | },
8 | "source": [
9 | "# Assignment 5: Data visualization\n",
10 | "Indira Sen, Claire Jordan, Elena Solar, Andri Rutschmann\n",
11 | "\n",
12 | "Winter Term 2023 / 2024\n",
13 | "\n",
14 | "In this fifth assignment we will practice data vizualization techniques. You can score up to 15 points in this assignment. Please submit your solutions inside this notebook in your repository on GitHub. The deadline for submission is on Friday, October 20, 23:00 hours. You will get individual feedback in your repository."
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": null,
20 | "metadata": {
21 | "id": "LT5rZK_-gOyM"
22 | },
23 | "outputs": [],
24 | "source": [
25 | "import numpy as np\n",
26 | "import matplotlib.pyplot as plt\n",
27 | "%matplotlib inline"
28 | ]
29 | },
30 | {
31 | "cell_type": "markdown",
32 | "metadata": {
33 | "id": "f0U5WmpYgOyO"
34 | },
35 | "source": [
36 | "# Toy data"
37 | ]
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "metadata": {
42 | "id": "Wu2xvrbngOyO"
43 | },
44 | "source": [
45 | "## 1. Create a scatter plot for the following data (2 points)"
46 | ]
47 | },
48 | {
49 | "cell_type": "code",
50 | "execution_count": null,
51 | "metadata": {
52 | "id": "WiynGMw3gOyP"
53 | },
54 | "outputs": [],
55 | "source": [
56 | "age = [32,34,19,33,57,15,62,65,32,17]\n",
57 | "income = [52000,27000,7000,23000,18500,50000,72000,22000,42000,0]"
58 | ]
59 | },
60 | {
61 | "cell_type": "markdown",
62 | "metadata": {
63 | "id": "O69eSsV4gOyQ"
64 | },
65 | "source": [
66 | "## 2. Create a simple line plot with two lines comparing the following measurements (1 point)\n",
67 | "\n"
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": null,
73 | "metadata": {
74 | "id": "HAgZc8osgOyR"
75 | },
76 | "outputs": [],
77 | "source": [
78 | "weather_station_1 = [22,17,18,19,25,26,28,17,15,12]\n",
79 | "weather_station_2 = [24,19,17,18,24,27,29,15,14,10]"
80 | ]
81 | },
82 | {
83 | "cell_type": "markdown",
84 | "metadata": {
85 | "id": "Mnyk81qtgOyR"
86 | },
87 | "source": [
88 | "## 3. Style this plot (1 point)\n",
89 | "The line colors should be red and blue; Add a legend; set the visible area for the y-axis from -5 to 35"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "metadata": {
96 | "id": "vmk570wZgOyS"
97 | },
98 | "outputs": [],
99 | "source": []
100 | },
101 | {
102 | "cell_type": "markdown",
103 | "metadata": {
104 | "id": "yL6WShOkgOyT"
105 | },
106 | "source": [
107 | "## 4. Visualize the following election data with a paired bar chart (1 point)"
108 | ]
109 | },
110 | {
111 | "cell_type": "code",
112 | "execution_count": null,
113 | "metadata": {},
114 | "outputs": [],
115 | "source": [
116 | "parties = [\"CDU\",\"SPD\",\"AfD\", \"FDP\", \"DIE LINKE\", \"GRÜNE\", \"CSU\", \"Sonstige\"]\n",
117 | "result_2017 = [26.8,20.5,12.6,10.7,9.2,8.9,6.2,5.0]\n",
118 | "result_2013 = [34.1,25.7,4.7,4.8,8.6,8.4,7.4,6.2]"
119 | ]
120 | },
121 | {
122 | "cell_type": "code",
123 | "execution_count": null,
124 | "metadata": {
125 | "id": "uCAM-7hygOyU"
126 | },
127 | "outputs": [],
128 | "source": []
129 | },
130 | {
131 | "cell_type": "markdown",
132 | "metadata": {
133 | "id": "gAt1VfCtgOyU"
134 | },
135 | "source": [
136 | "## 5.Create two pie charts for the following election data (2 points)"
137 | ]
138 | },
139 | {
140 | "cell_type": "code",
141 | "execution_count": null,
142 | "metadata": {
143 | "id": "SIT_-LDKgOyV"
144 | },
145 | "outputs": [],
146 | "source": []
147 | },
148 | {
149 | "cell_type": "markdown",
150 | "metadata": {
151 | "id": "u3hmt0EngOyV"
152 | },
153 | "source": [
154 | "# Quality of Government dataset"
155 | ]
156 | },
157 | {
158 | "cell_type": "code",
159 | "execution_count": null,
160 | "metadata": {
161 | "id": "ccVBJbUKgOyV"
162 | },
163 | "outputs": [],
164 | "source": [
165 | "import pandas as pd"
166 | ]
167 | },
168 | {
169 | "cell_type": "code",
170 | "execution_count": null,
171 | "metadata": {
172 | "id": "SgMaL11xgOyV"
173 | },
174 | "outputs": [],
175 | "source": [
176 | "#read the data directly online:\n",
177 | "data = pd.read_csv (\"http://www.qogdata.pol.gu.se/dataarchive/qog_std_cs_jan17.csv\")\n",
178 | "df = data [[\"cname\", \"wdi_pop\", \"wdi_popgr\", \"wdi_gdpcapcur\", \"wdi_gdpcapgr\", \"wdi_area\", \"wdi_broadb\", \"ht_region\"]]\n",
179 | "df.columns = [\"name\", \"population\",\"population_growth\", \"gdp_per_capita\", \"gdp_growth\", \"area\", \"internet\", \"region\"]\n",
180 | "df.region = df.region.replace (range(1,11) , [\"Eastern Europe\", \"Latin America\", \"North Africa & Middle East\", \"Sub-Saharan Africa\", \"Western Europe and North America\", \"East Asia\",\"South-East Asia\", \"South Asia\", \"Pacific\", \"Caribbean\"])\n"
181 | ]
182 | },
183 | {
184 | "cell_type": "code",
185 | "execution_count": null,
186 | "metadata": {
187 | "id": "Af1a2CsvgOyW"
188 | },
189 | "outputs": [],
190 | "source": [
191 | "# lets pre-compute the population density for each country, we will need it a couple of times\n",
192 | "df [\"population_density\"] = df.population / df.area"
193 | ]
194 | },
195 | {
196 | "cell_type": "markdown",
197 | "metadata": {
198 | "id": "gya7IVaFgOyW"
199 | },
200 | "source": [
201 | "## 5. Plot a bar chart of the population density in each country. Sort the bars in descending order of the population density (2 points)\n",
202 | "\n"
203 | ]
204 | },
205 | {
206 | "cell_type": "code",
207 | "execution_count": null,
208 | "metadata": {
209 | "id": "sUx3nLIVgOyX"
210 | },
211 | "outputs": [],
212 | "source": []
213 | },
214 | {
215 | "cell_type": "markdown",
216 | "metadata": {
217 | "id": "u_Em-ISogOyX"
218 | },
219 | "source": [
220 | "## 6. Plot a bar chart for the population in each country. Test the effect of using a logarithmic scale on the y-axis (2 points)"
221 | ]
222 | },
223 | {
224 | "cell_type": "code",
225 | "execution_count": null,
226 | "metadata": {
227 | "id": "IwK2K9EvgOyX"
228 | },
229 | "outputs": [],
230 | "source": []
231 | },
232 | {
233 | "cell_type": "markdown",
234 | "metadata": {
235 | "id": "F85p9mX9gOyX"
236 | },
237 | "source": [
238 | "## 7. Plot a histogram for the attribute 'population_growth' (1 point)"
239 | ]
240 | },
241 | {
242 | "cell_type": "code",
243 | "execution_count": null,
244 | "metadata": {
245 | "id": "aBY3C9t5gOyX"
246 | },
247 | "outputs": [],
248 | "source": []
249 | },
250 | {
251 | "cell_type": "markdown",
252 | "metadata": {
253 | "id": "ccrLEJzFgOyY"
254 | },
255 | "source": [
256 | "## 8. Compute the average (per country) population_growth and gdp_per_capita for each region. Plot these in a scatter plot against each other (2 points)"
257 | ]
258 | },
259 | {
260 | "cell_type": "code",
261 | "execution_count": null,
262 | "metadata": {
263 | "id": "xjVXcg8LgOyY"
264 | },
265 | "outputs": [],
266 | "source": []
267 | },
268 | {
269 | "cell_type": "markdown",
270 | "metadata": {
271 | "id": "8jHJOhgygOyY"
272 | },
273 | "source": [
274 | "## 9. Bonus: Add to the last plot a label (region name) for each region (1 point)"
275 | ]
276 | },
277 | {
278 | "cell_type": "code",
279 | "execution_count": null,
280 | "metadata": {
281 | "id": "f0s_TpJBgOyZ"
282 | },
283 | "outputs": [],
284 | "source": []
285 | }
286 | ],
287 | "metadata": {
288 | "colab": {
289 | "provenance": []
290 | },
291 | "kernelspec": {
292 | "display_name": "Python 3 (ipykernel)",
293 | "language": "python",
294 | "name": "python3"
295 | },
296 | "language_info": {
297 | "codemirror_mode": {
298 | "name": "ipython",
299 | "version": 3
300 | },
301 | "file_extension": ".py",
302 | "mimetype": "text/x-python",
303 | "name": "python",
304 | "nbconvert_exporter": "python",
305 | "pygments_lexer": "ipython3",
306 | "version": "3.9.13"
307 | },
308 | "nav_menu": {},
309 | "toc": {
310 | "base_numbering": 1,
311 | "nav_menu": {},
312 | "number_sections": true,
313 | "sideBar": true,
314 | "skip_h1_title": false,
315 | "title_cell": "Table of Contents",
316 | "title_sidebar": "Contents",
317 | "toc_cell": false,
318 | "toc_position": {},
319 | "toc_section_display": "block",
320 | "toc_window_display": false
321 | },
322 | "varInspector": {
323 | "cols": {
324 | "lenName": 16,
325 | "lenType": 16,
326 | "lenVar": 40
327 | },
328 | "kernels_config": {
329 | "python": {
330 | "delete_cmd_postfix": "",
331 | "delete_cmd_prefix": "del ",
332 | "library": "var_list.py",
333 | "varRefreshCmd": "print(var_dic_list())"
334 | },
335 | "r": {
336 | "delete_cmd_postfix": ") ",
337 | "delete_cmd_prefix": "rm(",
338 | "library": "var_list.r",
339 | "varRefreshCmd": "cat(var_dic_list()) "
340 | }
341 | },
342 | "types_to_exclude": [
343 | "module",
344 | "function",
345 | "builtin_function_or_method",
346 | "instance",
347 | "_Feature"
348 | ],
349 | "window_display": false
350 | }
351 | },
352 | "nbformat": 4,
353 | "nbformat_minor": 4
354 | }
355 |
--------------------------------------------------------------------------------
/SEDS_23/day 5_Friday/assignment/mini_project.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "04278307",
6 | "metadata": {
7 | "id": "04278307"
8 | },
9 | "source": [
10 | "# Project\n",
11 | "In this final assignment you will get the chance to complete a small data project on data you are personally interested in. You will need to get your own data, preprocess and analyze the data and visualize your findings. In this way, you will wrap up everything what you have learned in this course.\n",
12 | "
\n",
13 | "There is a lot of interesting data in the internet. We want to give you the opportunity to explore data which is in your own personal interest.\n",
14 | "
\n",
15 | "
\n",
16 | "Note: Please make sure comment your code and use new code chunks at relevant positions (i.e. after print()-statements). This makes corrections way easier.\n",
17 | "
\n",
18 | "
\n",
19 | "*adapted from: Prof. Dr. Karsten Donnay, Stefan Scholz (see [github repo](https://github.com/stefan-scholz/python-block-course-2019))*"
20 | ]
21 | },
22 | {
23 | "cell_type": "markdown",
24 | "id": "51d31cb5",
25 | "metadata": {
26 | "id": "51d31cb5"
27 | },
28 | "source": [
29 | "### Data collection:"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "id": "e3cb7d51",
35 | "metadata": {
36 | "id": "e3cb7d51"
37 | },
38 | "source": [
39 | "
\n",
40 | " Exercise (5 Points): Think of a data set, you want to build your project upon and look for one online. Describe what this data set is and for what reason it is interesting. Retrieve the data by either using webscraping or an API. If you are unsure, how to do this, have a look at the notebook (also feel free to get help online, i.e. YouTube Videos).\n",
41 | "
\n",
42 | "
\n",
43 | " Note: In the worst case, if you really can not come up with a dataset, downloading a csv-file and importing it is fine. But we can only give one point for this task. Sources could be kaggle.com or the dataset search by google.\n",
44 | "
"
45 | ]
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": null,
50 | "id": "a8004c82",
51 | "metadata": {
52 | "id": "a8004c82",
53 | "outputId": "48651024-9ffc-4f26-8dc1-ca20ec954d41"
54 | },
55 | "outputs": [],
56 | "source": []
57 | },
58 | {
59 | "cell_type": "markdown",
60 | "id": "48544e42",
61 | "metadata": {
62 | "id": "48544e42"
63 | },
64 | "source": [
65 | "### Data preprocessing:"
66 | ]
67 | },
68 | {
69 | "cell_type": "markdown",
70 | "id": "e80dd06e",
71 | "metadata": {
72 | "id": "e80dd06e"
73 | },
74 | "source": [
75 | "\n",
76 | " Exercise (5 Points): Get familiar with your data. Depending on your data, adjust and modify them using the methods we indroduced (i.e changing column names, or data types, select relevant columns, handle missing values, group and compute summary statistics).\n",
77 | "
"
78 | ]
79 | },
80 | {
81 | "cell_type": "code",
82 | "execution_count": null,
83 | "id": "f3dfd58c",
84 | "metadata": {
85 | "id": "f3dfd58c",
86 | "outputId": "d29506f0-e96e-4fc5-8954-e681b552842c"
87 | },
88 | "outputs": [],
89 | "source": []
90 | },
91 | {
92 | "cell_type": "markdown",
93 | "id": "0638e602",
94 | "metadata": {
95 | "id": "0638e602"
96 | },
97 | "source": [
98 | "### Data analysis and visualization:"
99 | ]
100 | },
101 | {
102 | "cell_type": "markdown",
103 | "id": "206f210b",
104 | "metadata": {
105 | "id": "206f210b"
106 | },
107 | "source": [
108 | "\n",
109 | " Exercise (5 Points): Visualize your 2-3 most important findings with the help of interesting visualizations. Use different types of plots and make sure to define a plots characteristics like colors, legends or else. Describe what you see and how to interprete the findings.\n",
110 | " If you have more things, you'd like to visualize and play around - feel free :)\n",
111 | "
"
112 | ]
113 | },
114 | {
115 | "cell_type": "code",
116 | "execution_count": null,
117 | "id": "1388ede9",
118 | "metadata": {
119 | "id": "1388ede9",
120 | "outputId": "d6566d60-160b-49e0-ab2f-cb310374b31c"
121 | },
122 | "outputs": [],
123 | "source": []
124 | }
125 | ],
126 | "metadata": {
127 | "colab": {
128 | "provenance": []
129 | },
130 | "kernelspec": {
131 | "display_name": "Python 3 (ipykernel)",
132 | "language": "python",
133 | "name": "python3"
134 | },
135 | "language_info": {
136 | "codemirror_mode": {
137 | "name": "ipython",
138 | "version": 3
139 | },
140 | "file_extension": ".py",
141 | "mimetype": "text/x-python",
142 | "name": "python",
143 | "nbconvert_exporter": "python",
144 | "pygments_lexer": "ipython3",
145 | "version": "3.9.13"
146 | },
147 | "vscode": {
148 | "interpreter": {
149 | "hash": "8a31fc8654382fa70e01b8b1b084ed875bc80468ef06668984d01fe98600013e"
150 | }
151 | }
152 | },
153 | "nbformat": 4,
154 | "nbformat_minor": 5
155 | }
156 |
--------------------------------------------------------------------------------
/SEDS_23/intro to python prep.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Indiiigo/Intro_to_python/3035764946d2c52d3d86d9e1db7ece284b0f59ee/SEDS_23/intro to python prep.pdf
--------------------------------------------------------------------------------
/SEDS_23/schedule + syllabus.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Indiiigo/Intro_to_python/3035764946d2c52d3d86d9e1db7ece284b0f59ee/SEDS_23/schedule + syllabus.pdf
--------------------------------------------------------------------------------
/day 0_ preparation/.ipynb_checkpoints/0_prep-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "R8_XlF1ZpR6P"
7 | },
8 | "source": [
9 | "# Introduction to Python\n",
10 | "\n",
11 | "## Setting up Python\n",
12 | "\n",
13 | "Make yourself acquainted with the notebook environment. It's basically a webpage with executable code. Code is run by clicking the \"run cell\" button (eighth from the left).\n",
14 | "\n",
15 | "There are many great keyboard shortcuts. Press 'H' to see a cheat sheet."
16 | ]
17 | },
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {
21 | "id": "qfTwQnaqpR6S"
22 | },
23 | "source": [
24 | "### Output\n",
25 | "\n",
26 | "Jupyter Notebook outputs the output of last line:"
27 | ]
28 | },
29 | {
30 | "cell_type": "code",
31 | "execution_count": null,
32 | "metadata": {
33 | "id": "yJPMAqN9pR6S"
34 | },
35 | "outputs": [],
36 | "source": [
37 | "1+1"
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "execution_count": null,
43 | "metadata": {
44 | "id": "w50VfKFypR6T"
45 | },
46 | "outputs": [],
47 | "source": [
48 | "1+1\n",
49 | "\"Hello!\""
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {
55 | "id": "JbHEQWiVpR6U"
56 | },
57 | "source": [
58 | "Using 'print' explictly allows you multiple print-outs per cell. Output by using Python's print function:"
59 | ]
60 | },
61 | {
62 | "cell_type": "code",
63 | "execution_count": null,
64 | "metadata": {
65 | "id": "Eb-tPAO0pR6U"
66 | },
67 | "outputs": [],
68 | "source": [
69 | "print(1+1)\n",
70 | "print(\"Hello!\")"
71 | ]
72 | },
73 | {
74 | "cell_type": "code",
75 | "execution_count": null,
76 | "metadata": {
77 | "id": "vcebsO-zpR6U"
78 | },
79 | "outputs": [],
80 | "source": []
81 | },
82 | {
83 | "cell_type": "markdown",
84 | "metadata": {
85 | "id": "4ZuYiyo6pR6U"
86 | },
87 | "source": [
88 | "### Imports\n",
89 | "\n",
90 | "A central building block of Python, and especially the distribution of Anaconda you should have installed, is the ability to import additional modules, packages or libraries into your current script with the 'import' command."
91 | ]
92 | },
93 | {
94 | "cell_type": "code",
95 | "execution_count": null,
96 | "metadata": {
97 | "id": "ztAuXRHYpR6V"
98 | },
99 | "outputs": [],
100 | "source": [
101 | "import math"
102 | ]
103 | },
104 | {
105 | "cell_type": "code",
106 | "execution_count": null,
107 | "metadata": {
108 | "id": "Ctn9X5yApR6V"
109 | },
110 | "outputs": [],
111 | "source": [
112 | "math.log(4)"
113 | ]
114 | },
115 | {
116 | "cell_type": "code",
117 | "execution_count": null,
118 | "metadata": {
119 | "id": "3ZlgpKzupR6V"
120 | },
121 | "outputs": [],
122 | "source": [
123 | "math.cos(math.pi)"
124 | ]
125 | },
126 | {
127 | "cell_type": "markdown",
128 | "metadata": {
129 | "id": "P69oIU4ZpR6V"
130 | },
131 | "source": [
132 | "Sometimes you will want to use a short name for a library:"
133 | ]
134 | },
135 | {
136 | "cell_type": "code",
137 | "execution_count": null,
138 | "metadata": {
139 | "id": "JYmwybp7pR6W"
140 | },
141 | "outputs": [],
142 | "source": [
143 | "import math as mt"
144 | ]
145 | },
146 | {
147 | "cell_type": "code",
148 | "execution_count": null,
149 | "metadata": {
150 | "id": "T2YEoERlpR6W"
151 | },
152 | "outputs": [],
153 | "source": [
154 | "mt.log(4)"
155 | ]
156 | },
157 | {
158 | "cell_type": "markdown",
159 | "metadata": {
160 | "id": "iUlcShu3pR6W"
161 | },
162 | "source": [
163 | "Note that you have to type the module name (\"math\" or \"mt\") before each function call.\n",
164 | "\n",
165 | "You can also import a specific function of a module. Then the explicit call is not necessary:"
166 | ]
167 | },
168 | {
169 | "cell_type": "code",
170 | "execution_count": null,
171 | "metadata": {
172 | "id": "qxZZTwSKpR6W"
173 | },
174 | "outputs": [],
175 | "source": [
176 | "from statistics import mean"
177 | ]
178 | },
179 | {
180 | "cell_type": "code",
181 | "execution_count": null,
182 | "metadata": {
183 | "id": "SxtkHAV6pR6W"
184 | },
185 | "outputs": [],
186 | "source": [
187 | "mean([2, 5, 6, 100])"
188 | ]
189 | },
190 | {
191 | "cell_type": "markdown",
192 | "metadata": {
193 | "id": "uNEBRO6ipR6W"
194 | },
195 | "source": [
196 | "Now that we know the basics of importing, make yourself comfortable with using multiple libraries. NumPy and Pandas are some of the ones we will be using in the course.\n"
197 | ]
198 | },
199 | {
200 | "cell_type": "markdown",
201 | "metadata": {
202 | "id": "lA9lE1a6pR6W"
203 | },
204 | "source": [
205 | "### NumPy\n",
206 | "\n",
207 | "NumPy is the fundamental package for scientific computing with Python. More information and tutorials at:\n",
208 | "\n",
209 | "http://www.numpy.org/"
210 | ]
211 | },
212 | {
213 | "cell_type": "code",
214 | "execution_count": null,
215 | "metadata": {
216 | "id": "Fga6y8xHpR6W"
217 | },
218 | "outputs": [],
219 | "source": [
220 | "import numpy as np"
221 | ]
222 | },
223 | {
224 | "cell_type": "markdown",
225 | "metadata": {
226 | "id": "zc4NFlQKpR6X"
227 | },
228 | "source": [
229 | "An example command:"
230 | ]
231 | },
232 | {
233 | "cell_type": "code",
234 | "execution_count": null,
235 | "metadata": {
236 | "id": "vO3haL-ipR6X"
237 | },
238 | "outputs": [],
239 | "source": [
240 | "x = [2, 5, 6, 100]\n",
241 | "np.mean(x)"
242 | ]
243 | },
244 | {
245 | "cell_type": "markdown",
246 | "metadata": {
247 | "id": "3VBE_T2UpR6X"
248 | },
249 | "source": [
250 | "### Pandas\n",
251 | "\n",
252 | "Pandas provides data structures and data analysis tools. More information and tutorials at:\n",
253 | "\n",
254 | "http://pandas.pydata.org/\n",
255 | "\n",
256 | "Import the pandas module as alias pd:"
257 | ]
258 | },
259 | {
260 | "cell_type": "code",
261 | "execution_count": null,
262 | "metadata": {
263 | "id": "J9PQf5dRpR6X"
264 | },
265 | "outputs": [],
266 | "source": [
267 | "import pandas as pd"
268 | ]
269 | },
270 | {
271 | "cell_type": "markdown",
272 | "metadata": {
273 | "id": "x2u84oqgpR6X"
274 | },
275 | "source": [
276 | "An example command:"
277 | ]
278 | },
279 | {
280 | "cell_type": "code",
281 | "execution_count": null,
282 | "metadata": {
283 | "id": "FKxHgWAXpR6X"
284 | },
285 | "outputs": [],
286 | "source": [
287 | "s = pd.Series([1, 3, 5, np.nan, 6, 8])\n",
288 | "s"
289 | ]
290 | }
291 | ],
292 | "metadata": {
293 | "colab": {
294 | "provenance": []
295 | },
296 | "kernel_info": {
297 | "name": "python3"
298 | },
299 | "kernelspec": {
300 | "display_name": "Python 3 (ipykernel)",
301 | "language": "python",
302 | "name": "python3"
303 | },
304 | "language_info": {
305 | "codemirror_mode": {
306 | "name": "ipython",
307 | "version": 3
308 | },
309 | "file_extension": ".py",
310 | "mimetype": "text/x-python",
311 | "name": "python",
312 | "nbconvert_exporter": "python",
313 | "pygments_lexer": "ipython3",
314 | "version": "3.11.5"
315 | },
316 | "nav_menu": {},
317 | "nteract": {
318 | "version": "0.8.4"
319 | },
320 | "toc": {
321 | "base_numbering": 1,
322 | "nav_menu": {},
323 | "number_sections": true,
324 | "sideBar": true,
325 | "skip_h1_title": false,
326 | "title_cell": "Table of Contents",
327 | "title_sidebar": "Contents",
328 | "toc_cell": false,
329 | "toc_position": {},
330 | "toc_section_display": "block",
331 | "toc_window_display": true
332 | }
333 | },
334 | "nbformat": 4,
335 | "nbformat_minor": 1
336 | }
337 |
--------------------------------------------------------------------------------
/day 0_ preparation/0_prep.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "R8_XlF1ZpR6P"
7 | },
8 | "source": [
9 | "# Introduction to Python\n",
10 | "\n",
11 | "## Setting up Python\n",
12 | "\n",
13 | "Make yourself acquainted with the notebook environment. It's basically a webpage with executable code. Code is run by clicking the \"run cell\" button (eighth from the left).\n",
14 | "\n",
15 | "There are many great keyboard shortcuts. Press 'H' to see a cheat sheet."
16 | ]
17 | },
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {
21 | "id": "qfTwQnaqpR6S"
22 | },
23 | "source": [
24 | "### Output\n",
25 | "\n",
26 | "Jupyter Notebook outputs the output of last line:"
27 | ]
28 | },
29 | {
30 | "cell_type": "code",
31 | "execution_count": null,
32 | "metadata": {
33 | "id": "yJPMAqN9pR6S"
34 | },
35 | "outputs": [],
36 | "source": [
37 | "1+1"
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "execution_count": null,
43 | "metadata": {
44 | "id": "w50VfKFypR6T"
45 | },
46 | "outputs": [],
47 | "source": [
48 | "1+1\n",
49 | "\"Hello!\""
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {
55 | "id": "JbHEQWiVpR6U"
56 | },
57 | "source": [
58 | "Using 'print' explictly allows you multiple print-outs per cell. Output by using Python's print function:"
59 | ]
60 | },
61 | {
62 | "cell_type": "code",
63 | "execution_count": null,
64 | "metadata": {
65 | "id": "Eb-tPAO0pR6U"
66 | },
67 | "outputs": [],
68 | "source": [
69 | "print(1+1)\n",
70 | "print(\"Hello!\")"
71 | ]
72 | },
73 | {
74 | "cell_type": "code",
75 | "execution_count": null,
76 | "metadata": {
77 | "id": "vcebsO-zpR6U"
78 | },
79 | "outputs": [],
80 | "source": []
81 | },
82 | {
83 | "cell_type": "markdown",
84 | "metadata": {
85 | "id": "4ZuYiyo6pR6U"
86 | },
87 | "source": [
88 | "### Imports\n",
89 | "\n",
90 | "A central building block of Python, and especially the distribution of Anaconda you should have installed, is the ability to import additional modules, packages or libraries into your current script with the 'import' command."
91 | ]
92 | },
93 | {
94 | "cell_type": "code",
95 | "execution_count": null,
96 | "metadata": {
97 | "id": "ztAuXRHYpR6V"
98 | },
99 | "outputs": [],
100 | "source": [
101 | "import math"
102 | ]
103 | },
104 | {
105 | "cell_type": "code",
106 | "execution_count": null,
107 | "metadata": {
108 | "id": "Ctn9X5yApR6V"
109 | },
110 | "outputs": [],
111 | "source": [
112 | "math.log(4)"
113 | ]
114 | },
115 | {
116 | "cell_type": "code",
117 | "execution_count": null,
118 | "metadata": {
119 | "id": "3ZlgpKzupR6V"
120 | },
121 | "outputs": [],
122 | "source": [
123 | "math.cos(math.pi)"
124 | ]
125 | },
126 | {
127 | "cell_type": "markdown",
128 | "metadata": {
129 | "id": "P69oIU4ZpR6V"
130 | },
131 | "source": [
132 | "Sometimes you will want to use a short name for a library:"
133 | ]
134 | },
135 | {
136 | "cell_type": "code",
137 | "execution_count": null,
138 | "metadata": {
139 | "id": "JYmwybp7pR6W"
140 | },
141 | "outputs": [],
142 | "source": [
143 | "import math as mt"
144 | ]
145 | },
146 | {
147 | "cell_type": "code",
148 | "execution_count": null,
149 | "metadata": {
150 | "id": "T2YEoERlpR6W"
151 | },
152 | "outputs": [],
153 | "source": [
154 | "mt.log(4)"
155 | ]
156 | },
157 | {
158 | "cell_type": "markdown",
159 | "metadata": {
160 | "id": "iUlcShu3pR6W"
161 | },
162 | "source": [
163 | "Note that you have to type the module name (\"math\" or \"mt\") before each function call.\n",
164 | "\n",
165 | "You can also import a specific function of a module. Then the explicit call is not necessary:"
166 | ]
167 | },
168 | {
169 | "cell_type": "code",
170 | "execution_count": null,
171 | "metadata": {
172 | "id": "qxZZTwSKpR6W"
173 | },
174 | "outputs": [],
175 | "source": [
176 | "from statistics import mean"
177 | ]
178 | },
179 | {
180 | "cell_type": "code",
181 | "execution_count": null,
182 | "metadata": {
183 | "id": "SxtkHAV6pR6W"
184 | },
185 | "outputs": [],
186 | "source": [
187 | "mean([2, 5, 6, 100])"
188 | ]
189 | },
190 | {
191 | "cell_type": "markdown",
192 | "metadata": {
193 | "id": "uNEBRO6ipR6W"
194 | },
195 | "source": [
196 | "Now that we know the basics of importing, make yourself comfortable with using multiple libraries. NumPy and Pandas are some of the ones we will be using in the course.\n"
197 | ]
198 | },
199 | {
200 | "cell_type": "markdown",
201 | "metadata": {
202 | "id": "lA9lE1a6pR6W"
203 | },
204 | "source": [
205 | "### NumPy\n",
206 | "\n",
207 | "NumPy is the fundamental package for scientific computing with Python. More information and tutorials at:\n",
208 | "\n",
209 | "http://www.numpy.org/"
210 | ]
211 | },
212 | {
213 | "cell_type": "code",
214 | "execution_count": null,
215 | "metadata": {
216 | "id": "Fga6y8xHpR6W"
217 | },
218 | "outputs": [],
219 | "source": [
220 | "import numpy as np"
221 | ]
222 | },
223 | {
224 | "cell_type": "markdown",
225 | "metadata": {
226 | "id": "zc4NFlQKpR6X"
227 | },
228 | "source": [
229 | "An example command:"
230 | ]
231 | },
232 | {
233 | "cell_type": "code",
234 | "execution_count": null,
235 | "metadata": {
236 | "id": "vO3haL-ipR6X"
237 | },
238 | "outputs": [],
239 | "source": [
240 | "x = [2, 5, 6, 100]\n",
241 | "np.mean(x)"
242 | ]
243 | },
244 | {
245 | "cell_type": "markdown",
246 | "metadata": {
247 | "id": "3VBE_T2UpR6X"
248 | },
249 | "source": [
250 | "### Pandas\n",
251 | "\n",
252 | "Pandas provides data structures and data analysis tools. More information and tutorials at:\n",
253 | "\n",
254 | "http://pandas.pydata.org/\n",
255 | "\n",
256 | "Import the pandas module as alias pd:"
257 | ]
258 | },
259 | {
260 | "cell_type": "code",
261 | "execution_count": null,
262 | "metadata": {
263 | "id": "J9PQf5dRpR6X"
264 | },
265 | "outputs": [],
266 | "source": [
267 | "import pandas as pd"
268 | ]
269 | },
270 | {
271 | "cell_type": "markdown",
272 | "metadata": {
273 | "id": "x2u84oqgpR6X"
274 | },
275 | "source": [
276 | "An example command:"
277 | ]
278 | },
279 | {
280 | "cell_type": "code",
281 | "execution_count": null,
282 | "metadata": {
283 | "id": "FKxHgWAXpR6X"
284 | },
285 | "outputs": [],
286 | "source": [
287 | "s = pd.Series([1, 3, 5, np.nan, 6, 8])\n",
288 | "s"
289 | ]
290 | }
291 | ],
292 | "metadata": {
293 | "colab": {
294 | "provenance": []
295 | },
296 | "kernel_info": {
297 | "name": "python3"
298 | },
299 | "kernelspec": {
300 | "display_name": "Python 3 (ipykernel)",
301 | "language": "python",
302 | "name": "python3"
303 | },
304 | "language_info": {
305 | "codemirror_mode": {
306 | "name": "ipython",
307 | "version": 3
308 | },
309 | "file_extension": ".py",
310 | "mimetype": "text/x-python",
311 | "name": "python",
312 | "nbconvert_exporter": "python",
313 | "pygments_lexer": "ipython3",
314 | "version": "3.11.5"
315 | },
316 | "nav_menu": {},
317 | "nteract": {
318 | "version": "0.8.4"
319 | },
320 | "toc": {
321 | "base_numbering": 1,
322 | "nav_menu": {},
323 | "number_sections": true,
324 | "sideBar": true,
325 | "skip_h1_title": false,
326 | "title_cell": "Table of Contents",
327 | "title_sidebar": "Contents",
328 | "toc_cell": false,
329 | "toc_position": {},
330 | "toc_section_display": "block",
331 | "toc_window_display": true
332 | }
333 | },
334 | "nbformat": 4,
335 | "nbformat_minor": 1
336 | }
337 |
--------------------------------------------------------------------------------
/day 0_ preparation/intro to python prep.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Indiiigo/Intro_to_python/3035764946d2c52d3d86d9e1db7ece284b0f59ee/day 0_ preparation/intro to python prep.pdf
--------------------------------------------------------------------------------
/day 1_ Monday/assignment/.ipynb_checkpoints/ex_1-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "SN-mb9j3Yc1X"
7 | },
8 | "source": [
9 | "# Assignment 1: Python basics and programming fundamentals\n",
10 | "Indira Sen\n",
11 | "\n",
12 | "In this first assignment we will practice how to use Jupyter Notebooks and how to execute Python code. "
13 | ]
14 | },
15 | {
16 | "cell_type": "markdown",
17 | "metadata": {
18 | "id": "QjcesK4dZSw4"
19 | },
20 | "source": [
21 | "## Ex 1\n",
22 | "\n",
23 | "This exercise covers variables. (total: 6 points)\n",
24 | "\n",
25 | "1. Use some of the arithmetic operations you want and do some calculations. (1 point)\n",
26 | "Bonus: By using `.format()` method to print outputs in such a format \"1+1=2\" (1 point)\n",
27 | "\n",
28 | "2. Define variables a = 16, b = 4 and c = 2.\n",
29 | "\n",
30 | " a.Print result of a/b*c+c (1 points)\n",
31 | "\n",
32 | " b.Do the same calculation but force multiplication to be first and then sum and finally division (by using parentheses) (1 point)\n",
33 | "\n",
34 | "3. Define a sentence and print it's length in a sentence in format of \"The length of 'sentence' is 8.\" (use `.format()` method) (2 points)"
35 | ]
36 | },
37 | {
38 | "cell_type": "code",
39 | "execution_count": null,
40 | "metadata": {
41 | "id": "VscuYWW0ZWlM"
42 | },
43 | "outputs": [],
44 | "source": []
45 | },
46 | {
47 | "cell_type": "markdown",
48 | "metadata": {
49 | "id": "SeX48MfjYc1Z"
50 | },
51 | "source": [
52 | "## Ex 2\n",
53 | "This exercise covers variables, lists, and if-statements (total: 5 points)"
54 | ]
55 | },
56 | {
57 | "cell_type": "markdown",
58 | "metadata": {
59 | "id": "0SF9mdqjYc1a"
60 | },
61 | "source": [
62 | "1. Make a list of names that includes at least four people. (1 point)\n",
63 | "2. Write an if test that prints a message about the room being crowded, if there are more than three people in your list. (1 point)\n",
64 | "3. Modify your list so that there are only two people in it. Use one of the methods for removing people from the list, don't just redefine the list. (2 points)\n",
65 | "4. Add some names to your list, so that there are at least six people in the list. Use one of the methods for appending people from the list, don't just redefine the list. (1 point)"
66 | ]
67 | },
68 | {
69 | "cell_type": "code",
70 | "execution_count": null,
71 | "metadata": {
72 | "id": "t4SnJYWHYc1a"
73 | },
74 | "outputs": [],
75 | "source": []
76 | },
77 | {
78 | "cell_type": "markdown",
79 | "metadata": {
80 | "id": "72ZcTAGWYc1b"
81 | },
82 | "source": [
83 | "## Ex 3\n",
84 | "This exercise covers variables, lists, and if-statements (total: 4 points)"
85 | ]
86 | },
87 | {
88 | "cell_type": "markdown",
89 | "metadata": {
90 | "id": "-7-5-5waYc1b"
91 | },
92 | "source": [
93 | "1. Create a list of lists where each sub list holds the arguments for the function. Loop this list of lists and first check if the length of inner list is not 2, then print an error message \"Length of numbers must be 2!\" and continue to the next iteration (use the `continue` statement). Otherwise call the function and print the result of the function. (2 points)\n",
94 | "\n",
95 | "2. Test your code by this list of lists: `number_lists = [[1, 1], [\"five\", 3], [5, \"three\"], [2, 2, 2], [5.5, 8]]` (1 point)\n",
96 | "\n",
97 | "3. Replace `continue` statement with `break` statement and run your code again. Could you notice the difference? (1 point)"
98 | ]
99 | },
100 | {
101 | "cell_type": "code",
102 | "execution_count": null,
103 | "metadata": {
104 | "id": "BRivZfxYYc1b"
105 | },
106 | "outputs": [],
107 | "source": []
108 | }
109 | ],
110 | "metadata": {
111 | "colab": {
112 | "provenance": []
113 | },
114 | "kernelspec": {
115 | "display_name": "Python 3 (ipykernel)",
116 | "language": "python",
117 | "name": "python3"
118 | },
119 | "language_info": {
120 | "codemirror_mode": {
121 | "name": "ipython",
122 | "version": 3
123 | },
124 | "file_extension": ".py",
125 | "mimetype": "text/x-python",
126 | "name": "python",
127 | "nbconvert_exporter": "python",
128 | "pygments_lexer": "ipython3",
129 | "version": "3.11.5"
130 | },
131 | "toc": {
132 | "base_numbering": 1,
133 | "nav_menu": {},
134 | "number_sections": false,
135 | "sideBar": false,
136 | "skip_h1_title": true,
137 | "title_cell": "Table of Contents",
138 | "title_sidebar": "Contents",
139 | "toc_cell": false,
140 | "toc_position": {},
141 | "toc_section_display": false,
142 | "toc_window_display": false
143 | }
144 | },
145 | "nbformat": 4,
146 | "nbformat_minor": 1
147 | }
148 |
--------------------------------------------------------------------------------
/day 1_ Monday/assignment/.ipynb_checkpoints/ex_2-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "SN-mb9j3Yc1X"
7 | },
8 | "source": [
9 | "# Assignment 2: Python basics and programming fundamentals\n",
10 | "Indira Sen\n",
11 | "\n",
12 | "In this assignment we will practice how to use more advanced data structure like dictionaries."
13 | ]
14 | },
15 | {
16 | "cell_type": "markdown",
17 | "metadata": {
18 | "id": "K8UhXKdwYc1b"
19 | },
20 | "source": [
21 | "## Ex 1"
22 | ]
23 | },
24 | {
25 | "cell_type": "markdown",
26 | "metadata": {
27 | "id": "vCY9U6Q2Yc1b"
28 | },
29 | "source": [
30 | "\n",
31 | "#### Mountain Heights 3\n",
32 | "- This is an extension of [Mountain Heights](#exercise_mountain_heights). Make sure you save this program under a different filename, such as *mountain\\_heights_3.py*, so that you can go back to your original program if you need to.\n",
33 | "\n",
34 | "A. The list of [tallest mountains in the world](http://en.wikipedia.org/wiki/List_of_mountains_by_elevation) provided all elevations in meters. Convert each of these elevations to feet, given that a meter is approximately 3.28 feet. You can do these calculations by hand at this point. (1 point)\n",
35 | "\n",
36 | "B. Create a new dictionary, where the keys of the dictionary are still the mountains' names. This time however, the values of the dictionary should be a list of each mountain's elevation in meters, and then in feet: {'everest': [8848, 29029]} (1 point)\n",
37 | "\n",
38 | "C. Print out just the mountains' names, by looping through the keys of your dictionary. (0.5 points)\n",
39 | "\n",
40 | "D. Print out just the mountains' elevations in meters, by looping through the values of your dictionary and pulling out the first number from each list. (0.5 points)\n",
41 | "\n",
42 | "E. Print out just the mountains' elevations in feet, by looping through the values of your dictionary and pulling out the second number from each list. (0.5 points)\n",
43 | "\n",
44 | "F. Print out a series of statements telling how tall each mountain is: \"Everest is 8848 meters tall, or 29029 feet.\" (1 point)\n",
45 | "\n",
46 | "G. Bonus: Start with your original program from [Mountain Heights](#exercise_mountain_heights). Write a function that reads through the elevations in meters, and returns a list of elevations in feet. Use this list to create the nested dictionary described above. (1 point)"
47 | ]
48 | },
49 | {
50 | "cell_type": "code",
51 | "execution_count": null,
52 | "metadata": {
53 | "id": "ubkwD2i09qKN"
54 | },
55 | "outputs": [],
56 | "source": []
57 | },
58 | {
59 | "cell_type": "markdown",
60 | "metadata": {
61 | "id": "drk1BMvSYc1c"
62 | },
63 | "source": [
64 | "## Ex 2"
65 | ]
66 | },
67 | {
68 | "cell_type": "markdown",
69 | "metadata": {
70 | "id": "u8IfFneKYc1c"
71 | },
72 | "source": [
73 | "#### Mountain Heights 4\n",
74 | "- This is one more extension of Mountain Heights.\n",
75 | "\n",
76 | "A. Create a new dictionary, where the keys of the dictionary are once again the mountains' names. This time, the values of the dictionary are another dictionary. This dictionary should contain the elevation in either meters or feet, and the range that contains the mountain. For example: {'everest': {'elevation': 8848, 'range': 'himalaya'}}. (2 points)\n",
77 | "\n",
78 | "B. Print out just the mountains' names. (0.5 points)\n",
79 | "\n",
80 | "C. Print out just the mountains' elevations. (0.5 points)\n",
81 | "\n",
82 | "D. Print out just the range for each mountain. (0.5 points)\n",
83 | "\n",
84 | "E. Print out a series of statements that say everything you know about each mountain: \"Everest is an 8848-meter tall mountain in the Himalaya range.\" (2 points)"
85 | ]
86 | },
87 | {
88 | "cell_type": "code",
89 | "execution_count": null,
90 | "metadata": {
91 | "id": "wPiWEzm1Yc1c"
92 | },
93 | "outputs": [],
94 | "source": []
95 | }
96 | ],
97 | "metadata": {
98 | "colab": {
99 | "provenance": []
100 | },
101 | "kernelspec": {
102 | "display_name": "Python 3 (ipykernel)",
103 | "language": "python",
104 | "name": "python3"
105 | },
106 | "language_info": {
107 | "codemirror_mode": {
108 | "name": "ipython",
109 | "version": 3
110 | },
111 | "file_extension": ".py",
112 | "mimetype": "text/x-python",
113 | "name": "python",
114 | "nbconvert_exporter": "python",
115 | "pygments_lexer": "ipython3",
116 | "version": "3.11.5"
117 | },
118 | "toc": {
119 | "base_numbering": 1,
120 | "nav_menu": {},
121 | "number_sections": false,
122 | "sideBar": false,
123 | "skip_h1_title": true,
124 | "title_cell": "Table of Contents",
125 | "title_sidebar": "Contents",
126 | "toc_cell": false,
127 | "toc_position": {},
128 | "toc_section_display": false,
129 | "toc_window_display": false
130 | }
131 | },
132 | "nbformat": 4,
133 | "nbformat_minor": 1
134 | }
135 |
--------------------------------------------------------------------------------
/day 1_ Monday/assignment/.ipynb_checkpoints/ex_2_answers-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "SN-mb9j3Yc1X"
7 | },
8 | "source": [
9 | "# Exercise: Introduction to Python & Basic Concepts"
10 | ]
11 | },
12 | {
13 | "cell_type": "markdown",
14 | "metadata": {
15 | "id": "K8UhXKdwYc1b"
16 | },
17 | "source": [
18 | "## Dictionary Exercises 1"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {
24 | "id": "vCY9U6Q2Yc1b"
25 | },
26 | "source": [
27 | "\n",
28 | "#### Mountain Heights 3\n",
29 | "- This is an extension of [Mountain Heights](#exercise_mountain_heights). Make sure you save this program under a different filename, such as *mountain\\_heights_3.py*, so that you can go back to your original program if you need to.\n",
30 | " - The list of [tallest mountains in the world](http://en.wikipedia.org/wiki/List_of_mountains_by_elevation) provided all elevations in meters. Convert each of these elevations to feet, given that a meter is approximately 3.28 feet. You can do these calculations by hand at this point.\n",
31 | " - Create a new dictionary, where the keys of the dictionary are still the mountains' names. This time however, the values of the dictionary should be a list of each mountain's elevation in meters, and then in feet: {'everest': [8848, 29029]}\n",
32 | " - Print out just the mountains' names, by looping through the keys of your dictionary.\n",
33 | " - Print out just the mountains' elevations in meters, by looping through the values of your dictionary and pulling out the first number from each list.\n",
34 | " - Print out just the mountains' elevations in feet, by looping through the values of your dictionary and pulling out the second number from each list.\n",
35 | " - Print out a series of statements telling how tall each mountain is: \"Everest is 8848 meters tall, or 29029 feet.\"\n",
36 | "- Bonus:\n",
37 | " - Start with your original program from [Mountain Heights](#exercise_mountain_heights). Write a function that reads through the elevations in meters, and returns a list of elevations in feet. Use this list to create the nested dictionary described above."
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "execution_count": null,
43 | "metadata": {
44 | "id": "ubkwD2i09qKN"
45 | },
46 | "outputs": [],
47 | "source": [
48 | "mountain_dict = {\"Mount Everest\": 8448, \"K2\": 8611, \"Kanchenjunga\":8586, \"Lhotse\" : 8516, \"Cho Oyu\" : 8201}\n",
49 | "\n",
50 | "mountain_dict_2 = {}\n",
51 | "\n",
52 | "for mountain_name in mountain_dict:\n",
53 | "\tmountain_dict_2[mountain_name] = [mountain_dict[mountain_name], mountain_dict[mountain_name] * 3.82 ]\n",
54 | "\n",
55 | "# Print out just the mountains' names, by looping through the keys of your dictionary.\n",
56 | "\n",
57 | "for mountain_name in mountain_dict_2:\n",
58 | "\tprint(\"{} is a mountain.\".format(mountain_name))\n",
59 | "\n",
60 | "# Print out just the mountains' elevations in meters, by looping through the values of your dictionary and\n",
61 | "# pulling out the first number from each list.\n",
62 | "print()\n",
63 | "for mountain_height in mountain_dict_2.values():\n",
64 | "\tprint(\"{} is a mountain's height in meters.\".format(mountain_height[0]))\n",
65 | "\n",
66 | "# Print out just the mountains' elevations in feet, by looping through the values of your dictionary and\n",
67 | "# pulling out the second number from each list.\n",
68 | "print()\n",
69 | "for mountain_height in mountain_dict_2.values():\n",
70 | "\tprint(\"{} is a mountain's height in feet.\".format(mountain_height[1]))\n",
71 | "\n",
72 | "# Print out a series of statements telling how tall each mountain is: \"Everest is 8848 meters tall, or 29029 feet.\"\n",
73 | "print()\n",
74 | "for mountain_name in mountain_dict_2:\n",
75 | "\tprint(\"{} is {} meters tall, or {} feet tall.\".format(mountain_name, mountain_dict_2[mountain_name][0], mountain_dict_2[mountain_name][1]))"
76 | ]
77 | },
78 | {
79 | "cell_type": "markdown",
80 | "metadata": {
81 | "id": "drk1BMvSYc1c"
82 | },
83 | "source": [
84 | "## Dictionary Exercises 2"
85 | ]
86 | },
87 | {
88 | "cell_type": "markdown",
89 | "metadata": {
90 | "id": "u8IfFneKYc1c"
91 | },
92 | "source": [
93 | "#### Mountain Heights 4\n",
94 | "- This is one more extension of Mountain Heights.\n",
95 | " - Create a new dictionary, where the keys of the dictionary are once again the mountains' names. This time, the values of the dictionary are another dictionary. This dictionary should contain the elevation in either meters or feet, and the range that contains the mountain. For example: {'everest': {'elevation': 8848, 'range': 'himalaya'}}.\n",
96 | " - Print out just the mountains' names.\n",
97 | " - Print out just the mountains' elevations.\n",
98 | " - Print out just the range for each mountain.\n",
99 | " - Print out a series of statements that say everything you know about each mountain: \"Everest is an 8848-meter tall mountain in the Himalaya range.\""
100 | ]
101 | },
102 | {
103 | "cell_type": "code",
104 | "execution_count": null,
105 | "metadata": {
106 | "id": "wPiWEzm1Yc1c"
107 | },
108 | "outputs": [],
109 | "source": [
110 | "mountain_dict = {\"Mount Everest\": {'elevation': 8848, 'range': 'himalaya'},\n",
111 | "\t\t\t\t \"K2\": {'elevation': 8611, 'range': 'himalaya'},\n",
112 | "\t\t\t\t \"Kanchenjunga\": {'elevation': 8586, 'range': 'hindu kush'},\n",
113 | "\t\t\t\t \"Lhotse\" : {'elevation': 8516, 'range': 'himalaya'},\n",
114 | "\t\t\t\t \"Cho Oyu\" : {'elevation': 8201, 'range': 'himalaya'}}\n",
115 | "\n",
116 | "\n",
117 | "# Print out just the mountains' names.\n",
118 | "\n",
119 | "for mountain_name in mountain_dict:\n",
120 | "\tprint(\"{} is a mountain.\".format(mountain_name))\n",
121 | "\n",
122 | "# Print out just the mountains' elevations.\n",
123 | "print()\n",
124 | "for mountain_name in mountain_dict:\n",
125 | "\tprint(\"{} is a mountain's elevation.\".format(mountain_dict[mountain_name]['elevation']))\n",
126 | "\n",
127 | "# Print out just the range for each mountain.\n",
128 | "print()\n",
129 | "for mountain_name in mountain_dict:\n",
130 | "\tprint(\"{} is a mountain's elevation.\".format(mountain_dict[mountain_name]['range']))\n",
131 | "\n",
132 | "# Print out a series of statements that say everything you know about each mountain: \"Everest is an 8848-meter tall mountain in the Himalaya range.\"\n",
133 | "print()\n",
134 | "for mountain_name in mountain_dict:\n",
135 | "\tprint(\"{} is a {}-meter tall mountain in the {} range.\".format(mountain_name, mountain_dict[mountain_name]['elevation'], mountain_dict[mountain_name]['range']))"
136 | ]
137 | }
138 | ],
139 | "metadata": {
140 | "colab": {
141 | "provenance": []
142 | },
143 | "kernelspec": {
144 | "display_name": "Python 3 (ipykernel)",
145 | "language": "python",
146 | "name": "python3"
147 | },
148 | "language_info": {
149 | "codemirror_mode": {
150 | "name": "ipython",
151 | "version": 3
152 | },
153 | "file_extension": ".py",
154 | "mimetype": "text/x-python",
155 | "name": "python",
156 | "nbconvert_exporter": "python",
157 | "pygments_lexer": "ipython3",
158 | "version": "3.11.5"
159 | },
160 | "toc": {
161 | "base_numbering": 1,
162 | "nav_menu": {},
163 | "number_sections": false,
164 | "sideBar": false,
165 | "skip_h1_title": true,
166 | "title_cell": "Table of Contents",
167 | "title_sidebar": "Contents",
168 | "toc_cell": false,
169 | "toc_position": {},
170 | "toc_section_display": false,
171 | "toc_window_display": false
172 | }
173 | },
174 | "nbformat": 4,
175 | "nbformat_minor": 1
176 | }
177 |
--------------------------------------------------------------------------------
/day 1_ Monday/assignment/ex_1.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "SN-mb9j3Yc1X"
7 | },
8 | "source": [
9 | "# Assignment 1: Python basics and programming fundamentals\n",
10 | "Indira Sen\n",
11 | "\n",
12 | "In this first assignment we will practice how to use Jupyter Notebooks and how to execute Python code. "
13 | ]
14 | },
15 | {
16 | "cell_type": "markdown",
17 | "metadata": {
18 | "id": "QjcesK4dZSw4"
19 | },
20 | "source": [
21 | "## Ex 1\n",
22 | "\n",
23 | "This exercise covers variables. (total: 6 points)\n",
24 | "\n",
25 | "1. Use some of the arithmetic operations you want and do some calculations. (1 point)\n",
26 | "Bonus: By using `.format()` method to print outputs in such a format \"1+1=2\" (1 point)\n",
27 | "\n",
28 | "2. Define variables a = 16, b = 4 and c = 2.\n",
29 | "\n",
30 | " a.Print result of a/b*c+c (1 points)\n",
31 | "\n",
32 | " b.Do the same calculation but force multiplication to be first and then sum and finally division (by using parentheses) (1 point)\n",
33 | "\n",
34 | "3. Define a sentence and print it's length in a sentence in format of \"The length of 'sentence' is 8.\" (use `.format()` method) (2 points)"
35 | ]
36 | },
37 | {
38 | "cell_type": "code",
39 | "execution_count": null,
40 | "metadata": {
41 | "id": "VscuYWW0ZWlM"
42 | },
43 | "outputs": [],
44 | "source": []
45 | },
46 | {
47 | "cell_type": "markdown",
48 | "metadata": {
49 | "id": "SeX48MfjYc1Z"
50 | },
51 | "source": [
52 | "## Ex 2\n",
53 | "This exercise covers variables, lists, and if-statements (total: 5 points)"
54 | ]
55 | },
56 | {
57 | "cell_type": "markdown",
58 | "metadata": {
59 | "id": "0SF9mdqjYc1a"
60 | },
61 | "source": [
62 | "1. Make a list of names that includes at least four people. (1 point)\n",
63 | "2. Write an if test that prints a message about the room being crowded, if there are more than three people in your list. (1 point)\n",
64 | "3. Modify your list so that there are only two people in it. Use one of the methods for removing people from the list, don't just redefine the list. (2 points)\n",
65 | "4. Add some names to your list, so that there are at least six people in the list. Use one of the methods for appending people from the list, don't just redefine the list. (1 point)"
66 | ]
67 | },
68 | {
69 | "cell_type": "code",
70 | "execution_count": null,
71 | "metadata": {
72 | "id": "t4SnJYWHYc1a"
73 | },
74 | "outputs": [],
75 | "source": []
76 | },
77 | {
78 | "cell_type": "markdown",
79 | "metadata": {
80 | "id": "72ZcTAGWYc1b"
81 | },
82 | "source": [
83 | "## Ex 3\n",
84 | "This exercise covers variables, lists, and if-statements (total: 4 points)"
85 | ]
86 | },
87 | {
88 | "cell_type": "markdown",
89 | "metadata": {
90 | "id": "-7-5-5waYc1b"
91 | },
92 | "source": [
93 | "1. Create a list of lists where each sub list holds the arguments for the function. Loop this list of lists and first check if the length of inner list is not 2, then print an error message \"Length of numbers must be 2!\" and continue to the next iteration (use the `continue` statement). Otherwise call the function and print the result of the function. (2 points)\n",
94 | "\n",
95 | "2. Test your code by this list of lists: `number_lists = [[1, 1], [\"five\", 3], [5, \"three\"], [2, 2, 2], [5.5, 8]]` (1 point)\n",
96 | "\n",
97 | "3. Replace `continue` statement with `break` statement and run your code again. Could you notice the difference? (1 point)"
98 | ]
99 | },
100 | {
101 | "cell_type": "code",
102 | "execution_count": null,
103 | "metadata": {
104 | "id": "BRivZfxYYc1b"
105 | },
106 | "outputs": [],
107 | "source": []
108 | }
109 | ],
110 | "metadata": {
111 | "colab": {
112 | "provenance": []
113 | },
114 | "kernelspec": {
115 | "display_name": "Python 3 (ipykernel)",
116 | "language": "python",
117 | "name": "python3"
118 | },
119 | "language_info": {
120 | "codemirror_mode": {
121 | "name": "ipython",
122 | "version": 3
123 | },
124 | "file_extension": ".py",
125 | "mimetype": "text/x-python",
126 | "name": "python",
127 | "nbconvert_exporter": "python",
128 | "pygments_lexer": "ipython3",
129 | "version": "3.11.5"
130 | },
131 | "toc": {
132 | "base_numbering": 1,
133 | "nav_menu": {},
134 | "number_sections": false,
135 | "sideBar": false,
136 | "skip_h1_title": true,
137 | "title_cell": "Table of Contents",
138 | "title_sidebar": "Contents",
139 | "toc_cell": false,
140 | "toc_position": {},
141 | "toc_section_display": false,
142 | "toc_window_display": false
143 | }
144 | },
145 | "nbformat": 4,
146 | "nbformat_minor": 1
147 | }
148 |
--------------------------------------------------------------------------------
/day 1_ Monday/assignment/ex_1_answers.ipynb:
--------------------------------------------------------------------------------
1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"SN-mb9j3Yc1X"},"source":["# Exercise: Introduction to Python & Basic Concepts"]},{"cell_type":"markdown","source":["## Ex 1\n","\n","This exercise covers variables.\n","\n","1. Use some of the arithmetic operations you want and do some calculations.\n"," 1. Optional: By using `.format()` method to print outputs in such a format \"1+1=2\"\n","\n","2. Define variables a = 16, b = 4 and c = 2.\n"," 1. Print result of a/b*c+c\n"," 2. Do the same calculation but force multiplication to be first and then sum and finally division (by using parentheses)\n","\n","3. Define a sentence and print it's length in a sentence in format of \"The length of 'sentence' is 8.\" (use `.format()` method)"],"metadata":{"id":"QjcesK4dZSw4"}},{"cell_type":"code","source":["print(\"######## Part 1:\")\n","#Use some of the arithmetic operations you want and do some calculations.\n","result = 1+1\n","print(\"1+1={}\".format(result))\n","result = 5-1\n","print(\"5-1={}\".format(result))\n","result = 6*3\n","print(\"6*3={}\".format(result))\n","result = 6/3\n","print(\"6/3={}\".format(result))\n","result = 5//3\n","print(\"5//3={}\".format(result))\n","result = 5%3\n","print(\"5%3={}\".format(result))\n","result = 2**3\n","print(\"2**3={}\".format(result))\n","\n","print(\"######## Part 2:\")\n","# Define variables a = 16, b = 4 and c = 2.\n","a = 16\n","b = 4\n","c = 2\n","\n","# Print result of a/b*c+c\n","result = a/b*c+c\n","print(\"a/b*c+c={}\".format(result))\n","\n","# Do the same calculation but force multiplication to be first and then sumd and finally division (by using parentheses)\n","result = a/((b*c)+c)\n","print(\"a/((b*c)+c)={}\".format(result))\n","\n","print(\"######## Part 3:\")\n","# Define a sentence and print it's length.\n","sent = \"Define a sentence and print it's length.\"\n","print(\"The length of '{}' is {}.\".format(sent, len(sent)))"],"metadata":{"id":"VscuYWW0ZWlM","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1696845936792,"user_tz":-120,"elapsed":7,"user":{"displayName":"Indira Sen","userId":"11191672663586892835"}},"outputId":"dc77e4cd-485a-4a44-d3d7-ce1df88483b7"},"execution_count":1,"outputs":[{"output_type":"stream","name":"stdout","text":["######## Part 1:\n","1+1=2\n","5-1=4\n","6*3=18\n","6/3=2.0\n","5//3=1\n","5%3=2\n","2**3=8\n","######## Part 2:\n","a/b*c+c=10.0\n","a/((b*c)+c)=1.6\n","######## Part 3:\n","The length of 'Define a sentence and print it's length.' is 40.\n"]}]},{"cell_type":"markdown","metadata":{"id":"SeX48MfjYc1Z"},"source":["## Ex 2\n","This exercise covers variables and lists"]},{"cell_type":"markdown","metadata":{"id":"0SF9mdqjYc1a"},"source":["1. Make a list of names that includes at least four people.\n","2. Write an if test that prints a message about the room being crowded, if there are more than three people in your list.\n","3. Modify your list so that there are only two people in it. Use one of the methods for removing people from the list, don't just redefine the list.\n","4. Add some names to your list, so that there are at least six people in the list. Use one of the methods for appending people from the list, don't just redefine the list."]},{"cell_type":"code","execution_count":2,"metadata":{"id":"t4SnJYWHYc1a","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1696846043604,"user_tz":-120,"elapsed":264,"user":{"displayName":"Indira Sen","userId":"11191672663586892835"}},"outputId":"50561fcb-a29f-4872-9c4f-61e126a64a6f"},"outputs":[{"output_type":"stream","name":"stdout","text":["####### step 1\n","['adele', 'ken', 'cody', 'caroline']\n","####### step 2\n","The room is crowded, there are 4 people.\n","####### step 3\n","['adele', 'ken']\n","####### step 4\n"]}],"source":["print(\"####### step 1\")\n","# Make a list of names that includes at least four people.\n","people = [\"adele\", \"ken\", \"cody\", \"caroline\"]\n","print(people)\n","\n","print(\"####### step 2\")\n","# Write an if test that prints a message about the room being crowded, if there are more than three people in your list.\n","if len(people) >= 3:\n"," print(\"The room is crowded, there are {} people.\".format(len(people)))\n","\n","print(\"####### step 3\")\n","# Modify your list so that there are only two people in it.\n","people.remove(\"cody\")\n","people.remove(\"caroline\")\n","print(people)\n","\n","print(\"####### step 4\")\n","# Add some names to your list, so that there are at least six people in the list.\n","people.append(\"cody\")\n","people.append(\"caroline\")\n","people.append(\"adriana\")\n","people.append(\"billy\")"]},{"cell_type":"markdown","metadata":{"id":"72ZcTAGWYc1b"},"source":["## Ex 3\n","This exercise covers variables and lists"]},{"cell_type":"markdown","metadata":{"id":"-7-5-5waYc1b"},"source":["1. Create a list of lists where each sub list holds the arguments for the function. Loop this list of lists and first check if the length of inner list is not 2, then print an error message \"Length of numbers must be 2!\" and continue to the next iteration (use the `continue` statement). Otherwise call the function and print the result of the function.\n","\n","2. Test your code by this list of lists: `number_lists = [[1, 1], [\"five\", 3], [5, \"three\"], [2, 2, 2], [5.5, 8]]`\n","\n","3. Replace `continue` statement with `break` statement and run your code again. Could you notice the difference?"]},{"cell_type":"code","execution_count":4,"metadata":{"id":"BRivZfxYYc1b","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1696846318095,"user_tz":-120,"elapsed":236,"user":{"displayName":"Indira Sen","userId":"11191672663586892835"}},"outputId":"98fde862-86c0-4658-b4c5-46d781fd3fcd"},"outputs":[{"output_type":"stream","name":"stdout","text":["1 1 : 1\n","Invalid input: five\n","five 3 : 0\n","Invalid input: three\n","5 three : 0\n","Length of numbers must be 2!\n","5.5 8 : 44.0\n"]}],"source":["number_lists = [[1, 1], [\"five\", 3], [5, \"three\"], [2, 2, 2], [5.5, 8]]\n","for numbers in number_lists:\n"," if len(numbers) != 2:\n"," print(\"Length of numbers must be 2!\")\n"," continue\n"," else:\n"," result = 0\n"," # check type of first number, it must be int or float\n"," n1 = numbers[0]\n"," n2 = numbers[1]\n"," if type(n1) != int and type(n1) != float:\n"," print(\"Invalid input: {}\".format(n1))\n"," # check type of second number, it must be int or float\n"," elif type(n2) != int and type(n2) != float:\n"," print(\"Invalid input: {}\".format(n2))\n"," else:\n"," # do the calculation and return the result\n"," result = n1 * n2\n","\n"," print(numbers[0], numbers[1], \":\", result)"]},{"cell_type":"code","execution_count":5,"metadata":{"id":"wPiWEzm1Yc1c","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1696846332965,"user_tz":-120,"elapsed":257,"user":{"displayName":"Indira Sen","userId":"11191672663586892835"}},"outputId":"a6cbc065-a6d3-4272-a06c-acd4392a4b89"},"outputs":[{"output_type":"stream","name":"stdout","text":["1 1 : 1\n","Invalid input: five\n","five 3 : 0\n","Invalid input: three\n","5 three : 0\n","Length of numbers must be 2!\n"]}],"source":["number_lists = [[1, 1], [\"five\", 3], [5, \"three\"], [2, 2, 2], [5.5, 8]]\n","for numbers in number_lists:\n"," if len(numbers) != 2:\n"," print(\"Length of numbers must be 2!\")\n"," break\n"," else:\n"," result = 0\n"," # check type of first number, it must be int or float\n"," n1 = numbers[0]\n"," n2 = numbers[1]\n"," if type(n1) != int and type(n1) != float:\n"," print(\"Invalid input: {}\".format(n1))\n"," # check type of second number, it must be int or float\n"," elif type(n2) != int and type(n2) != float:\n"," print(\"Invalid input: {}\".format(n2))\n"," else:\n"," # do the calculation and return the result\n"," result = n1 * n2\n","\n"," print(numbers[0], numbers[1], \":\", result)"]},{"cell_type":"code","source":[],"metadata":{"id":"9EkA-bAZ7EC-"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 2","language":"python","name":"python2"},"language_info":{"codemirror_mode":{"name":"ipython","version":2},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython2","version":"2.7.12"},"toc":{"base_numbering":1,"nav_menu":{},"number_sections":false,"sideBar":false,"skip_h1_title":true,"title_cell":"Table of Contents","title_sidebar":"Contents","toc_cell":false,"toc_position":{},"toc_section_display":false,"toc_window_display":false},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0}
--------------------------------------------------------------------------------
/day 1_ Monday/assignment/ex_2.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "SN-mb9j3Yc1X"
7 | },
8 | "source": [
9 | "# Assignment 2: Python basics and programming fundamentals\n",
10 | "Indira Sen\n",
11 | "\n",
12 | "In this assignment we will practice how to use more advanced data structure like dictionaries."
13 | ]
14 | },
15 | {
16 | "cell_type": "markdown",
17 | "metadata": {
18 | "id": "K8UhXKdwYc1b"
19 | },
20 | "source": [
21 | "## Ex 1"
22 | ]
23 | },
24 | {
25 | "cell_type": "markdown",
26 | "metadata": {
27 | "id": "vCY9U6Q2Yc1b"
28 | },
29 | "source": [
30 | "\n",
31 | "#### Mountain Heights 3\n",
32 | "- This is an extension of [Mountain Heights](#exercise_mountain_heights). Make sure you save this program under a different filename, such as *mountain\\_heights_3.py*, so that you can go back to your original program if you need to.\n",
33 | "\n",
34 | "A. The list of [tallest mountains in the world](http://en.wikipedia.org/wiki/List_of_mountains_by_elevation) provided all elevations in meters. Convert each of these elevations to feet, given that a meter is approximately 3.28 feet. You can do these calculations by hand at this point. (1 point)\n",
35 | "\n",
36 | "B. Create a new dictionary, where the keys of the dictionary are still the mountains' names. This time however, the values of the dictionary should be a list of each mountain's elevation in meters, and then in feet: {'everest': [8848, 29029]} (1 point)\n",
37 | "\n",
38 | "C. Print out just the mountains' names, by looping through the keys of your dictionary. (0.5 points)\n",
39 | "\n",
40 | "D. Print out just the mountains' elevations in meters, by looping through the values of your dictionary and pulling out the first number from each list. (0.5 points)\n",
41 | "\n",
42 | "E. Print out just the mountains' elevations in feet, by looping through the values of your dictionary and pulling out the second number from each list. (0.5 points)\n",
43 | "\n",
44 | "F. Print out a series of statements telling how tall each mountain is: \"Everest is 8848 meters tall, or 29029 feet.\" (1 point)\n",
45 | "\n",
46 | "G. Bonus: Start with your original program from [Mountain Heights](#exercise_mountain_heights). Write a function that reads through the elevations in meters, and returns a list of elevations in feet. Use this list to create the nested dictionary described above. (1 point)"
47 | ]
48 | },
49 | {
50 | "cell_type": "code",
51 | "execution_count": null,
52 | "metadata": {
53 | "id": "ubkwD2i09qKN"
54 | },
55 | "outputs": [],
56 | "source": []
57 | },
58 | {
59 | "cell_type": "markdown",
60 | "metadata": {
61 | "id": "drk1BMvSYc1c"
62 | },
63 | "source": [
64 | "## Ex 2"
65 | ]
66 | },
67 | {
68 | "cell_type": "markdown",
69 | "metadata": {
70 | "id": "u8IfFneKYc1c"
71 | },
72 | "source": [
73 | "#### Mountain Heights 4\n",
74 | "- This is one more extension of Mountain Heights.\n",
75 | "\n",
76 | "A. Create a new dictionary, where the keys of the dictionary are once again the mountains' names. This time, the values of the dictionary are another dictionary. This dictionary should contain the elevation in either meters or feet, and the range that contains the mountain. For example: {'everest': {'elevation': 8848, 'range': 'himalaya'}}. (2 points)\n",
77 | "\n",
78 | "B. Print out just the mountains' names. (0.5 points)\n",
79 | "\n",
80 | "C. Print out just the mountains' elevations. (0.5 points)\n",
81 | "\n",
82 | "D. Print out just the range for each mountain. (0.5 points)\n",
83 | "\n",
84 | "E. Print out a series of statements that say everything you know about each mountain: \"Everest is an 8848-meter tall mountain in the Himalaya range.\" (2 points)"
85 | ]
86 | },
87 | {
88 | "cell_type": "code",
89 | "execution_count": null,
90 | "metadata": {
91 | "id": "wPiWEzm1Yc1c"
92 | },
93 | "outputs": [],
94 | "source": []
95 | }
96 | ],
97 | "metadata": {
98 | "colab": {
99 | "provenance": []
100 | },
101 | "kernelspec": {
102 | "display_name": "Python 3 (ipykernel)",
103 | "language": "python",
104 | "name": "python3"
105 | },
106 | "language_info": {
107 | "codemirror_mode": {
108 | "name": "ipython",
109 | "version": 3
110 | },
111 | "file_extension": ".py",
112 | "mimetype": "text/x-python",
113 | "name": "python",
114 | "nbconvert_exporter": "python",
115 | "pygments_lexer": "ipython3",
116 | "version": "3.11.5"
117 | },
118 | "toc": {
119 | "base_numbering": 1,
120 | "nav_menu": {},
121 | "number_sections": false,
122 | "sideBar": false,
123 | "skip_h1_title": true,
124 | "title_cell": "Table of Contents",
125 | "title_sidebar": "Contents",
126 | "toc_cell": false,
127 | "toc_position": {},
128 | "toc_section_display": false,
129 | "toc_window_display": false
130 | }
131 | },
132 | "nbformat": 4,
133 | "nbformat_minor": 1
134 | }
135 |
--------------------------------------------------------------------------------
/day 1_ Monday/assignment/ex_2_answers.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "SN-mb9j3Yc1X"
7 | },
8 | "source": [
9 | "# Exercise: Introduction to Python & Basic Concepts"
10 | ]
11 | },
12 | {
13 | "cell_type": "markdown",
14 | "metadata": {
15 | "id": "K8UhXKdwYc1b"
16 | },
17 | "source": [
18 | "## Dictionary Exercises 1"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {
24 | "id": "vCY9U6Q2Yc1b"
25 | },
26 | "source": [
27 | "\n",
28 | "#### Mountain Heights 3\n",
29 | "- This is an extension of [Mountain Heights](#exercise_mountain_heights). Make sure you save this program under a different filename, such as *mountain\\_heights_3.py*, so that you can go back to your original program if you need to.\n",
30 | " - The list of [tallest mountains in the world](http://en.wikipedia.org/wiki/List_of_mountains_by_elevation) provided all elevations in meters. Convert each of these elevations to feet, given that a meter is approximately 3.28 feet. You can do these calculations by hand at this point.\n",
31 | " - Create a new dictionary, where the keys of the dictionary are still the mountains' names. This time however, the values of the dictionary should be a list of each mountain's elevation in meters, and then in feet: {'everest': [8848, 29029]}\n",
32 | " - Print out just the mountains' names, by looping through the keys of your dictionary.\n",
33 | " - Print out just the mountains' elevations in meters, by looping through the values of your dictionary and pulling out the first number from each list.\n",
34 | " - Print out just the mountains' elevations in feet, by looping through the values of your dictionary and pulling out the second number from each list.\n",
35 | " - Print out a series of statements telling how tall each mountain is: \"Everest is 8848 meters tall, or 29029 feet.\"\n",
36 | "- Bonus:\n",
37 | " - Start with your original program from [Mountain Heights](#exercise_mountain_heights). Write a function that reads through the elevations in meters, and returns a list of elevations in feet. Use this list to create the nested dictionary described above."
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "execution_count": null,
43 | "metadata": {
44 | "id": "ubkwD2i09qKN"
45 | },
46 | "outputs": [],
47 | "source": [
48 | "mountain_dict = {\"Mount Everest\": 8448, \"K2\": 8611, \"Kanchenjunga\":8586, \"Lhotse\" : 8516, \"Cho Oyu\" : 8201}\n",
49 | "\n",
50 | "mountain_dict_2 = {}\n",
51 | "\n",
52 | "for mountain_name in mountain_dict:\n",
53 | "\tmountain_dict_2[mountain_name] = [mountain_dict[mountain_name], mountain_dict[mountain_name] * 3.82 ]\n",
54 | "\n",
55 | "# Print out just the mountains' names, by looping through the keys of your dictionary.\n",
56 | "\n",
57 | "for mountain_name in mountain_dict_2:\n",
58 | "\tprint(\"{} is a mountain.\".format(mountain_name))\n",
59 | "\n",
60 | "# Print out just the mountains' elevations in meters, by looping through the values of your dictionary and\n",
61 | "# pulling out the first number from each list.\n",
62 | "print()\n",
63 | "for mountain_height in mountain_dict_2.values():\n",
64 | "\tprint(\"{} is a mountain's height in meters.\".format(mountain_height[0]))\n",
65 | "\n",
66 | "# Print out just the mountains' elevations in feet, by looping through the values of your dictionary and\n",
67 | "# pulling out the second number from each list.\n",
68 | "print()\n",
69 | "for mountain_height in mountain_dict_2.values():\n",
70 | "\tprint(\"{} is a mountain's height in feet.\".format(mountain_height[1]))\n",
71 | "\n",
72 | "# Print out a series of statements telling how tall each mountain is: \"Everest is 8848 meters tall, or 29029 feet.\"\n",
73 | "print()\n",
74 | "for mountain_name in mountain_dict_2:\n",
75 | "\tprint(\"{} is {} meters tall, or {} feet tall.\".format(mountain_name, mountain_dict_2[mountain_name][0], mountain_dict_2[mountain_name][1]))"
76 | ]
77 | },
78 | {
79 | "cell_type": "markdown",
80 | "metadata": {
81 | "id": "drk1BMvSYc1c"
82 | },
83 | "source": [
84 | "## Dictionary Exercises 2"
85 | ]
86 | },
87 | {
88 | "cell_type": "markdown",
89 | "metadata": {
90 | "id": "u8IfFneKYc1c"
91 | },
92 | "source": [
93 | "#### Mountain Heights 4\n",
94 | "- This is one more extension of Mountain Heights.\n",
95 | " - Create a new dictionary, where the keys of the dictionary are once again the mountains' names. This time, the values of the dictionary are another dictionary. This dictionary should contain the elevation in either meters or feet, and the range that contains the mountain. For example: {'everest': {'elevation': 8848, 'range': 'himalaya'}}.\n",
96 | " - Print out just the mountains' names.\n",
97 | " - Print out just the mountains' elevations.\n",
98 | " - Print out just the range for each mountain.\n",
99 | " - Print out a series of statements that say everything you know about each mountain: \"Everest is an 8848-meter tall mountain in the Himalaya range.\""
100 | ]
101 | },
102 | {
103 | "cell_type": "code",
104 | "execution_count": null,
105 | "metadata": {
106 | "id": "wPiWEzm1Yc1c"
107 | },
108 | "outputs": [],
109 | "source": [
110 | "mountain_dict = {\"Mount Everest\": {'elevation': 8848, 'range': 'himalaya'},\n",
111 | "\t\t\t\t \"K2\": {'elevation': 8611, 'range': 'himalaya'},\n",
112 | "\t\t\t\t \"Kanchenjunga\": {'elevation': 8586, 'range': 'hindu kush'},\n",
113 | "\t\t\t\t \"Lhotse\" : {'elevation': 8516, 'range': 'himalaya'},\n",
114 | "\t\t\t\t \"Cho Oyu\" : {'elevation': 8201, 'range': 'himalaya'}}\n",
115 | "\n",
116 | "\n",
117 | "# Print out just the mountains' names.\n",
118 | "\n",
119 | "for mountain_name in mountain_dict:\n",
120 | "\tprint(\"{} is a mountain.\".format(mountain_name))\n",
121 | "\n",
122 | "# Print out just the mountains' elevations.\n",
123 | "print()\n",
124 | "for mountain_name in mountain_dict:\n",
125 | "\tprint(\"{} is a mountain's elevation.\".format(mountain_dict[mountain_name]['elevation']))\n",
126 | "\n",
127 | "# Print out just the range for each mountain.\n",
128 | "print()\n",
129 | "for mountain_name in mountain_dict:\n",
130 | "\tprint(\"{} is a mountain's elevation.\".format(mountain_dict[mountain_name]['range']))\n",
131 | "\n",
132 | "# Print out a series of statements that say everything you know about each mountain: \"Everest is an 8848-meter tall mountain in the Himalaya range.\"\n",
133 | "print()\n",
134 | "for mountain_name in mountain_dict:\n",
135 | "\tprint(\"{} is a {}-meter tall mountain in the {} range.\".format(mountain_name, mountain_dict[mountain_name]['elevation'], mountain_dict[mountain_name]['range']))"
136 | ]
137 | }
138 | ],
139 | "metadata": {
140 | "colab": {
141 | "provenance": []
142 | },
143 | "kernelspec": {
144 | "display_name": "Python 3 (ipykernel)",
145 | "language": "python",
146 | "name": "python3"
147 | },
148 | "language_info": {
149 | "codemirror_mode": {
150 | "name": "ipython",
151 | "version": 3
152 | },
153 | "file_extension": ".py",
154 | "mimetype": "text/x-python",
155 | "name": "python",
156 | "nbconvert_exporter": "python",
157 | "pygments_lexer": "ipython3",
158 | "version": "3.11.5"
159 | },
160 | "toc": {
161 | "base_numbering": 1,
162 | "nav_menu": {},
163 | "number_sections": false,
164 | "sideBar": false,
165 | "skip_h1_title": true,
166 | "title_cell": "Table of Contents",
167 | "title_sidebar": "Contents",
168 | "toc_cell": false,
169 | "toc_position": {},
170 | "toc_section_display": false,
171 | "toc_window_display": false
172 | }
173 | },
174 | "nbformat": 4,
175 | "nbformat_minor": 1
176 | }
177 |
--------------------------------------------------------------------------------
/day 1_ Monday/notebooks/11_var_string_num_ex1_1.py:
--------------------------------------------------------------------------------
1 | # Store a message in a variable
2 | msg = "Hey"
3 | # Print that message
4 | print(msg)
5 |
6 | # Store a new message in the same variable
7 | msg = "How are you?"
8 | # Print that new message
9 | print(msg)
--------------------------------------------------------------------------------
/day 1_ Monday/notebooks/11_var_string_num_ex1_2.py:
--------------------------------------------------------------------------------
1 | print("####### Part 1:")
2 | # Store the quote in a variable.
3 | quote = "One of my most productive days was throwing away 1000 lines of code"
4 | # Store the full name of the person in another variable.
5 | person = "Ken Thompson"
6 |
7 | # Print a sentence in such format "X once said, 'quote comes here'."
8 | sentence = "{} once said, '{}'.".format(person, quote)
9 | print(sentence)
10 |
11 | print("####### Part 2:")
12 | # Store a first name and a last name, in lowercase, in 2 different variables.
13 | first_name = "name"
14 | last_name = "surname"
15 | # Using that variables store the full name in another variable (concatenation)
16 | full_name = first_name + " " + last_name
17 | # full_name = "{} {}".format(first_name, last_name)
18 |
19 | # Print the full name in lowercase, Titlecase, and UPPERCASE.
20 | print(full_name)
21 | print(full_name.lower())
22 | print(full_name.title())
23 | print(full_name.upper())
--------------------------------------------------------------------------------
/day 1_ Monday/notebooks/12_lists_tuples-1_ex1_1.py:
--------------------------------------------------------------------------------
1 | #Exercises
2 | """
3 |
4 | First Neat List
5 |
6 | Store the values 'python', 'c', and 'java' in a list. Print a statement about each of these values,
7 | using their position in the list.
8 | Your statement could simply be, 'A nice programming language is value.'
9 |
10 | """
11 |
12 |
13 | languages = ['python', 'c', 'java']
14 |
15 | print("A nice programming language is " + languages[0])
16 | print("A nice programming language is " + languages[1])
17 | print("A nice programming language is {}".format(languages[2]))
18 |
19 |
20 | print("\n")
21 |
22 |
23 | """
24 |
25 | Your First List
26 |
27 | Think of something you can store in a list. Make a list with three or four items,
28 | and then print a message that includes at least one item from your list.
29 | Your sentence could be as simple as, "One item in my list is a ____."
30 |
31 | """
32 |
33 | my_list = [3, 'my CD', 'Kessler', 2.5]
34 |
35 | print("The thing that I cannot live without is {}.".format(my_list[1]))
36 |
--------------------------------------------------------------------------------
/day 1_ Monday/notebooks/12_lists_tuples-1_ex1_2.py:
--------------------------------------------------------------------------------
1 | #Exercises
2 | """
3 |
4 | First Neat List - Loop
5 |
6 | Repeat First Neat List, but this time use a loop to print out your statements.
7 | Make sure you are writing the same sentence for all values in your list.
8 | Loops are not effective when you are trying to generate different output for each value in your list.
9 |
10 | """
11 | languages = ['python', 'c', 'java']
12 |
13 |
14 | for language in languages:
15 | print("A nice programming language is " + language)
16 |
17 |
18 | print("\n")
19 |
20 |
21 |
22 | """
23 |
24 | Your First List - Loop
25 |
26 | Repeat Your First List, but this time use a loop to print out your message for each item in your list.
27 | Again, if you came up with different messages for each value in your list, decide on one message to
28 | repeat for each value in your list.
29 |
30 | """
31 |
32 | my_list = [3, 'my CD', 'Kessler', 2.5]
33 |
34 | for thing in my_list:
35 | print("The thing that I cannot live without is {}.".format(thing))
36 |
37 |
--------------------------------------------------------------------------------
/day 1_ Monday/notebooks/13_if_statements_ex4_1.py:
--------------------------------------------------------------------------------
1 | print("####### Gymnast Scores - 2")
2 | scores = range(1, 11)
3 |
4 | for score in scores:
5 | # if score != 1:
6 | # if score >= 2:
7 | if score > 1:
8 | print("A judge can give a gymnast {} points.".format(score))
9 | else:
10 | print("A judge can give a gymnast {} point.".format(score))
11 |
12 | print("\n####### Numbers")
13 | saved_numbers = [2, 1, 5, 12, 42, 34, 52]
14 | new_numbers = [3, 1, 33, 52, 4]
15 |
16 | for new_number in new_numbers:
17 | if new_number not in saved_numbers:
18 | saved_numbers.append(new_number)
19 | print("{} is now saved".format(new_number))
20 | else:
21 | print("{} is already saved".format(new_number))
--------------------------------------------------------------------------------
/day 1_ Monday/notebooks/13_if_statements_ex4_2.py:
--------------------------------------------------------------------------------
1 | # Make a list of ten aliens, each of which is one color: 'red', 'green', or 'blue'.
2 | aliens = ["red", "green", "pink", "blue", "red", "blue", "green", "red", "red", "blue"]
3 | print("number of aliens:", len(aliens))
4 |
5 | # Use a for loop to determine the number of points a player would earn for destroying all of the aliens in your list
6 | current_score = 0
7 | for alien_color in aliens:
8 | if alien_color == "red":
9 | current_score = current_score + 5
10 | elif alien_color == "green":
11 | current_score = current_score + 10
12 | elif alien_color == "blue":
13 | current_score = current_score + 20
14 | else:
15 | print("I don't know points of color '{}'".format(alien_color))
16 | print("total points: {}".format(current_score))
--------------------------------------------------------------------------------
/day 1_ Monday/notebooks/14_lists_tuples-2_ex1_1.py:
--------------------------------------------------------------------------------
1 | """
2 | Working List
3 |
4 | Make a list that includes four careers, such as 'programmer' and 'truck driver'.
5 | """
6 | print("Part 1")
7 | careers = ['doctor', 'scientist', 'historian', 'teacher']
8 |
9 | print("\nUse the list.index() function to find the index of one career in your list.")
10 |
11 | print(careers.index('historian'))
12 |
13 | print("\nUse the in function to show that this career is in your list.")
14 |
15 | print('historian' in careers)
16 |
17 | print("\nUse the append() function to add a new career to your list.")
18 |
19 | careers.append('politician')
20 | print(careers)
21 |
22 | print("\nUse the insert() function to add a new career at the beginning of the list.")
23 |
24 | careers.insert(0, 'archeologist')
25 | print(careers)
26 | print("\n")
27 |
28 | """
29 | Ordered Working List
30 | """
31 |
32 | print("Start with the list you created in Working List.")
33 |
34 |
35 |
36 | print("\nYou are going to print out the list in a number of different orders.")
37 | print("Each time you print the list, use a for loop rather than printing the raw list.")
38 | print("Print a message each time telling us what order we should see the list in.")
39 |
40 | print("\nPrint the list in its original order.")
41 |
42 | for career in careers:
43 | print(career)
44 |
45 | print("\nPrint the list in alphabetical order.")
46 |
47 | for career in sorted(careers):
48 | print(career)
49 |
50 | print("\nPrint the list in reverse alphabetical order.")
51 |
52 | for career in sorted(careers, reverse = True):
53 | print(career)
54 |
55 | print("\nPermanently sort the list in alphabetical order, and then print it out.")
56 |
57 | careers.sort()
58 |
59 | for career in careers:
60 | print(career)
61 |
62 |
63 | print("\n")
64 | """
65 | List Lengths
66 | """
67 |
68 | print("Copy two or three of the lists you made from the previous exercises, or make up two or three new lists.")
69 |
70 | languages = ['python', 'c', 'java']
71 |
72 | print("\nPrint out a series of statements that tell us how long each list is.")
73 |
74 | print("the new_careers list is {} items long.".format(len(careers)))
75 | print("the languages list is {} items long.".format(len(languages)))
--------------------------------------------------------------------------------
/day 1_ Monday/notebooks/14_lists_tuples-2_ex1_2.py:
--------------------------------------------------------------------------------
1 | print("Gymnast Scores")
2 |
3 | print("Store the possible scores a gymnast can earn from one judge in a list.")
4 |
5 | scores = []
6 | for score in range(1,11):
7 | scores.append(score)
8 |
9 | print("\nPrint out the sentence, \"The lowest possible score is ___, and the highest possible score is ___.\" Use the values from your list.")
10 |
11 | print("The lowest possible score is {0}, and the highest possible score is {1}.".format(scores[0], scores[-1]))
12 |
13 |
14 | print("\nPrint out a series of sentences, \"A judge can give a gymnast ___ points.\"")
15 | print("\nDon't worry if your first sentence reads \"A judge can give a gymnast 1 points.")
16 |
17 | for score in scores:
18 | print("A judge can give a gymnast {} points.".format(score))
19 |
20 |
21 | print("\nHowever, you get 1000 bonus internet points if you can use a for loop, and have correct grammar.")
22 |
23 | print("A judge can give a gymnast {} point.".format(scores[0]))
24 | for score in scores[1:]:
25 | print("A judge can give a gymnast {} points.".format(score))
26 |
27 | print("\nPop the first five elements (by position) and remove the last(by value).")
28 | for score in range(1,5):
29 | scores.pop(0)
30 |
31 | print(scores)
32 |
33 | scores.remove(10)
34 |
35 | print(scores)
--------------------------------------------------------------------------------
/day 1_ Monday/notebooks/14_lists_tuples-2_ex1_3.py:
--------------------------------------------------------------------------------
1 | print("First Twenty")
2 |
3 | print("Use the range() function to store the first twenty numbers (1-20) in a list, and print them out.")
4 |
5 | first_twenty = range(1,21)
6 |
7 | for number in first_twenty:
8 | print(number)
9 |
10 | print("\nFive Wallets")
11 |
12 | print("Imagine five wallets with different amounts of cash in them. Store these five values in a list")
13 |
14 | wallets = [2000, 12, 456, 9, 10000]
15 |
16 | print("The fattest wallet has {} in it.".format(sorted(wallets, reverse = True)[0]))
17 | print("The skinniest wallet has {} in it.".format(sorted(wallets)[0]))
18 | print("All together, these wallets have $ {} in them.".format(sum(wallets)))
--------------------------------------------------------------------------------
/day 1_ Monday/notebooks/15_dictionaries_ex_1.py:
--------------------------------------------------------------------------------
1 | pets = {'Tom': 'cat', 'Spike' : 'dog', 'Jerry' : 'mouse', 'Remi' : 'rat'}
2 |
3 | pets['Tom'] = 'Persian cat'
4 | print(pets)
5 |
6 | pets['Black Beauty'] = 'horse'
7 | print(pets)
8 |
9 | del pets['Black Beauty']
10 | print(pets)
11 |
12 | print("Bonus")
13 |
14 | for key, val in pets.items():
15 | print( "%s : %s" %(key,val))
16 |
--------------------------------------------------------------------------------
/day 1_ Monday/notebooks/15_dictionaries_ex_2.py:
--------------------------------------------------------------------------------
1 | # Mountain Heights
2 |
3 | # Wikipedia has a list of the tallest mountains in the world, with each mountain's elevation. Pick five mountains from this list.
4 | print("Create a dictionary with the mountain names as keys, and the elevations as values.")
5 |
6 | mountain_dict = {"Mount Everest": 8448, "K2": 8611, "Kanchenjunga":8586, "Lhotse" : 8516, "Cho Oyu" : 8201}
7 |
8 | print("\n")
9 | print("Print out just the mountains\' names, by looping through the keys of your dictionary.")
10 | for key in mountain_dict.keys():
11 | print(key)
12 |
13 | print("\n")
14 | print("Print out just the mountains' elevations, by looping through the values of your dictionary.")
15 | for val in mountain_dict.values():
16 | print(val)
17 |
18 | print("\n")
19 | print("Print out a series of statements telling how tall each mountain is: \"Everest is 8848 meters tall.\"")
20 | for key, val in mountain_dict.items():
21 | print("%s is %d meters tall." %(key,val))
--------------------------------------------------------------------------------
/day 2_ Tuesday/assignment/.ipynb_checkpoints/ex_3-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "bGIGSnHXLvId"
7 | },
8 | "source": [
9 | "# Assignment 3: Loops, Functions, and Data Exploration with Pandas\n",
10 | "\n",
11 | "Indira Sen"
12 | ]
13 | },
14 | {
15 | "cell_type": "markdown",
16 | "metadata": {
17 | "id": "0tfnt0QN-98D"
18 | },
19 | "source": [
20 | "# Ex 1: Quality of Government Dataset (Total: 4.5 points)\n",
21 | "Read in the government dataset directly from \"http://www.qogdata.pol.gu.se/data/qog_std_cs_jan19.csv\"\n",
22 | "\n",
23 | "A. How many rows does this dataset have? (0.5 points)\n",
24 | "\n",
25 | "B. How many columns does this dataset have? (0.5 points)\n",
26 | "\n",
27 | "C. Select the following columns from the dataset:\n",
28 | "\"cname\", \"wdi_pop\", \"wdi_popgr\", \"wdi_gdpcapcur\", \"wdi_gdpcapgr\", \"wdi_area\", \"wdi_broadb\", \"ht_region\" into another dataframe (0.5 points)\n",
29 | "\n",
30 | "D. Rename the columns to: \"country\", \"population\",\"population_growth\", \"gdp_per_capita\", \"gdp_growth\", \"area\", \"internet\", \"region\" (0.5 points)\n",
31 | "\n",
32 | "E. Rename the region codes 1-10 with\n",
33 | "\"Eastern Europe\", \"Latin America\", \"North Africa & Middle East\", \"Sub-Saharan Africa\", \"Western Europe and North America\", \"East Asia\",\"South-East Asia\", \"South Asia\", \"Pacific\", \"Caribbean\" (1 point)\n",
34 | "\n",
35 | "F. What are the mean values for each attribute? (1 point)\n",
36 | "\n",
37 | "G. Which country has the highest population in the region \"Eastern Europe\"? (0.5 points)"
38 | ]
39 | },
40 | {
41 | "cell_type": "markdown",
42 | "metadata": {
43 | "id": "Sg6-DbsGLvBR"
44 | },
45 | "source": []
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": null,
50 | "metadata": {
51 | "id": "yhJWcviy-98G"
52 | },
53 | "outputs": [],
54 | "source": []
55 | },
56 | {
57 | "cell_type": "markdown",
58 | "metadata": {
59 | "id": "Svgbispj-98J"
60 | },
61 | "source": [
62 | "# Ex 2: Book and Movie shop (Total: 10.5 points)"
63 | ]
64 | },
65 | {
66 | "cell_type": "markdown",
67 | "metadata": {
68 | "id": "ZPpYj_nt-98K"
69 | },
70 | "source": [
71 | "For a virtual shop that sells movies and books, we have four tables:\n",
72 | " \n",
73 | " 1. pd_customers: Gives first- and lastname for each customer\n",
74 | " 2. pd_books: Gives the raw price for all books that are being sold\n",
75 | " 3. pd_movies: Gives the raw price for all movies that are being sold\n",
76 | " 4. pd_transactions: Gives the list of all transactions being made (which customer bought which item)\n",
77 | "\n",
78 | "Do the following:\n",
79 | "\n",
80 | "A. Load all 4 datasets in separate dataframes (2 points)\n",
81 | "\n",
82 | "B. Compile a listing of all items (=books and movies) that have been sold in one dataframe\n",
83 | "The dataframe should contain two columns: \"item_name\" and \"price\" (1 point)\n",
84 | "\n",
85 | "C. Join the information on customer names, transactions, and prices in one dataframe (1 point)\n",
86 | "\n",
87 | "D. Compute a table of customers. For all customers give the number of items bought, the sum of these items, and the average price of the item. (2 points)\n",
88 | "\n",
89 | "E. Extend that list such that it also contains customers without purchases (1 point)\n",
90 | "\n",
91 | "F. Round the price mean and the price sum to two digits and export the table to a .csv file (1.5 points)\n",
92 | "\n",
93 | "G. Compute lists of the top 10 bestselling items, both by count and by sum of prices (2 points)\n"
94 | ]
95 | },
96 | {
97 | "cell_type": "code",
98 | "execution_count": null,
99 | "metadata": {
100 | "id": "AOr8rbkk-98K"
101 | },
102 | "outputs": [],
103 | "source": []
104 | }
105 | ],
106 | "metadata": {
107 | "colab": {
108 | "provenance": []
109 | },
110 | "hide_input": false,
111 | "kernelspec": {
112 | "display_name": "Python 3 (ipykernel)",
113 | "language": "python",
114 | "name": "python3"
115 | },
116 | "language_info": {
117 | "codemirror_mode": {
118 | "name": "ipython",
119 | "version": 3
120 | },
121 | "file_extension": ".py",
122 | "mimetype": "text/x-python",
123 | "name": "python",
124 | "nbconvert_exporter": "python",
125 | "pygments_lexer": "ipython3",
126 | "version": "3.11.5"
127 | },
128 | "nav_menu": {},
129 | "toc": {
130 | "base_numbering": 1,
131 | "nav_menu": {},
132 | "number_sections": true,
133 | "sideBar": true,
134 | "skip_h1_title": false,
135 | "title_cell": "Table of Contents",
136 | "title_sidebar": "Contents",
137 | "toc_cell": false,
138 | "toc_position": {},
139 | "toc_section_display": false,
140 | "toc_window_display": false
141 | },
142 | "varInspector": {
143 | "cols": {
144 | "lenName": 16,
145 | "lenType": 16,
146 | "lenVar": 40
147 | },
148 | "kernels_config": {
149 | "python": {
150 | "delete_cmd_postfix": "",
151 | "delete_cmd_prefix": "del ",
152 | "library": "var_list.py",
153 | "varRefreshCmd": "print(var_dic_list())"
154 | },
155 | "r": {
156 | "delete_cmd_postfix": ") ",
157 | "delete_cmd_prefix": "rm(",
158 | "library": "var_list.r",
159 | "varRefreshCmd": "cat(var_dic_list()) "
160 | }
161 | },
162 | "types_to_exclude": [
163 | "module",
164 | "function",
165 | "builtin_function_or_method",
166 | "instance",
167 | "_Feature"
168 | ],
169 | "window_display": false
170 | }
171 | },
172 | "nbformat": 4,
173 | "nbformat_minor": 1
174 | }
175 |
--------------------------------------------------------------------------------
/day 2_ Tuesday/assignment/.ipynb_checkpoints/ex_4-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "VDM62QDIgOyE"
7 | },
8 | "source": [
9 | "# Assignment 5: Data visualization\n",
10 | "Indira Sen"
11 | ]
12 | },
13 | {
14 | "cell_type": "code",
15 | "execution_count": null,
16 | "metadata": {
17 | "id": "LT5rZK_-gOyM"
18 | },
19 | "outputs": [],
20 | "source": [
21 | "import numpy as np\n",
22 | "import matplotlib.pyplot as plt\n",
23 | "%matplotlib inline"
24 | ]
25 | },
26 | {
27 | "cell_type": "markdown",
28 | "metadata": {
29 | "id": "f0U5WmpYgOyO"
30 | },
31 | "source": [
32 | "# Toy data"
33 | ]
34 | },
35 | {
36 | "cell_type": "markdown",
37 | "metadata": {
38 | "id": "Wu2xvrbngOyO"
39 | },
40 | "source": [
41 | "## 1. Create a scatter plot for the following data (2 points)"
42 | ]
43 | },
44 | {
45 | "cell_type": "code",
46 | "execution_count": null,
47 | "metadata": {
48 | "id": "WiynGMw3gOyP"
49 | },
50 | "outputs": [],
51 | "source": [
52 | "age = [32,34,19,33,57,15,62,65,32,17]\n",
53 | "income = [52000,27000,7000,23000,18500,50000,72000,22000,42000,0]"
54 | ]
55 | },
56 | {
57 | "cell_type": "markdown",
58 | "metadata": {
59 | "id": "O69eSsV4gOyQ"
60 | },
61 | "source": [
62 | "## 2. Create a simple line plot with two lines comparing the following measurements (2 points)\n",
63 | "\n"
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": null,
69 | "metadata": {
70 | "id": "HAgZc8osgOyR"
71 | },
72 | "outputs": [],
73 | "source": [
74 | "weather_station_1 = [22,17,18,19,25,26,28,17,15,12]\n",
75 | "weather_station_2 = [24,19,17,18,24,27,29,15,14,10]"
76 | ]
77 | },
78 | {
79 | "cell_type": "markdown",
80 | "metadata": {
81 | "id": "Mnyk81qtgOyR"
82 | },
83 | "source": [
84 | "## 3. Style this plot (1 point)\n",
85 | "The line colors should be red and blue; Add a legend; set the visible area for the y-axis from -5 to 35"
86 | ]
87 | },
88 | {
89 | "cell_type": "code",
90 | "execution_count": null,
91 | "metadata": {
92 | "id": "vmk570wZgOyS"
93 | },
94 | "outputs": [],
95 | "source": []
96 | },
97 | {
98 | "cell_type": "markdown",
99 | "metadata": {
100 | "id": "yL6WShOkgOyT"
101 | },
102 | "source": [
103 | "## 4. Visualize the following election data with a paired bar chart"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": null,
109 | "metadata": {
110 | "id": "uCAM-7hygOyU"
111 | },
112 | "outputs": [],
113 | "source": [
114 | "parties = [\"CDU\",\"SPD\",\"AfD\", \"FDP\", \"DIE LINKE\", \"GRÜNE\", \"CSU\", \"Sonstige\"]\n",
115 | "result_2017 = [26.8,20.5,12.6,10.7,9.2,8.9,6.2,5.0]\n",
116 | "result_2013 = [34.1,25.7,4.7,4.8,8.6,8.4,7.4,6.2]"
117 | ]
118 | },
119 | {
120 | "cell_type": "markdown",
121 | "metadata": {
122 | "id": "gAt1VfCtgOyU"
123 | },
124 | "source": [
125 | "## Create two pie charts for the above election data (2 points)"
126 | ]
127 | },
128 | {
129 | "cell_type": "code",
130 | "execution_count": null,
131 | "metadata": {
132 | "id": "SIT_-LDKgOyV"
133 | },
134 | "outputs": [],
135 | "source": []
136 | },
137 | {
138 | "cell_type": "markdown",
139 | "metadata": {
140 | "id": "u3hmt0EngOyV"
141 | },
142 | "source": [
143 | "# Quality of Government dataset"
144 | ]
145 | },
146 | {
147 | "cell_type": "code",
148 | "execution_count": null,
149 | "metadata": {
150 | "id": "ccVBJbUKgOyV"
151 | },
152 | "outputs": [],
153 | "source": [
154 | "import pandas as pd"
155 | ]
156 | },
157 | {
158 | "cell_type": "code",
159 | "execution_count": null,
160 | "metadata": {
161 | "id": "SgMaL11xgOyV"
162 | },
163 | "outputs": [],
164 | "source": [
165 | "#read the data directly online:\n",
166 | "data = pd.read_csv (\"http://www.qogdata.pol.gu.se/dataarchive/qog_std_cs_jan17.csv\")\n",
167 | "df = data [[\"cname\", \"wdi_pop\", \"wdi_popgr\", \"wdi_gdpcapcur\", \"wdi_gdpcapgr\", \"wdi_area\", \"wdi_broadb\", \"ht_region\"]]\n",
168 | "df.columns = [\"name\", \"population\",\"population_growth\", \"gdp_per_capita\", \"gdp_growth\", \"area\", \"internet\", \"region\"]\n",
169 | "df.region = df.region.replace (range(1,11) , [\"Eastern Europe\", \"Latin America\", \"North Africa & Middle East\", \"Sub-Saharan Africa\", \"Western Europe and North America\", \"East Asia\",\"South-East Asia\", \"South Asia\", \"Pacific\", \"Caribbean\"])"
170 | ]
171 | },
172 | {
173 | "cell_type": "code",
174 | "execution_count": null,
175 | "metadata": {
176 | "id": "Af1a2CsvgOyW"
177 | },
178 | "outputs": [],
179 | "source": [
180 | "# lets pre-compute the population density for each country, we will need it a couple of times\n",
181 | "df [\"population_density\"] = df.population / df.area"
182 | ]
183 | },
184 | {
185 | "cell_type": "markdown",
186 | "metadata": {
187 | "id": "gya7IVaFgOyW"
188 | },
189 | "source": [
190 | "## 5. Plot a bar chart of the population density in each country. Sort the bars in descending order of the population density (2 points)\n",
191 | "\n"
192 | ]
193 | },
194 | {
195 | "cell_type": "code",
196 | "execution_count": null,
197 | "metadata": {
198 | "id": "sUx3nLIVgOyX"
199 | },
200 | "outputs": [],
201 | "source": []
202 | },
203 | {
204 | "cell_type": "markdown",
205 | "metadata": {
206 | "id": "u_Em-ISogOyX"
207 | },
208 | "source": [
209 | "## 6. Plot a bar chart for the population in each country. Test the effect of using a logarithmic scale on the y-axis (2 points)"
210 | ]
211 | },
212 | {
213 | "cell_type": "code",
214 | "execution_count": null,
215 | "metadata": {
216 | "id": "IwK2K9EvgOyX"
217 | },
218 | "outputs": [],
219 | "source": []
220 | },
221 | {
222 | "cell_type": "markdown",
223 | "metadata": {
224 | "id": "F85p9mX9gOyX"
225 | },
226 | "source": [
227 | "## 7. Plot a histogram for the attribute 'population_growth' (1 point)"
228 | ]
229 | },
230 | {
231 | "cell_type": "code",
232 | "execution_count": null,
233 | "metadata": {
234 | "id": "aBY3C9t5gOyX"
235 | },
236 | "outputs": [],
237 | "source": []
238 | },
239 | {
240 | "cell_type": "markdown",
241 | "metadata": {
242 | "id": "ccrLEJzFgOyY"
243 | },
244 | "source": [
245 | "## 8. Compute the average (per country) population_growth and gdp_per_capita for each region. Plot these in a scatter plot against each other (2 points)"
246 | ]
247 | },
248 | {
249 | "cell_type": "code",
250 | "execution_count": null,
251 | "metadata": {
252 | "id": "xjVXcg8LgOyY"
253 | },
254 | "outputs": [],
255 | "source": []
256 | },
257 | {
258 | "cell_type": "markdown",
259 | "metadata": {
260 | "id": "8jHJOhgygOyY"
261 | },
262 | "source": [
263 | "## 9. Bonus: Add to the last plot a label (region name) for each region (1 point)"
264 | ]
265 | },
266 | {
267 | "cell_type": "code",
268 | "execution_count": null,
269 | "metadata": {
270 | "id": "f0s_TpJBgOyZ"
271 | },
272 | "outputs": [],
273 | "source": []
274 | }
275 | ],
276 | "metadata": {
277 | "colab": {
278 | "provenance": []
279 | },
280 | "kernelspec": {
281 | "display_name": "Python 3 (ipykernel)",
282 | "language": "python",
283 | "name": "python3"
284 | },
285 | "language_info": {
286 | "codemirror_mode": {
287 | "name": "ipython",
288 | "version": 3
289 | },
290 | "file_extension": ".py",
291 | "mimetype": "text/x-python",
292 | "name": "python",
293 | "nbconvert_exporter": "python",
294 | "pygments_lexer": "ipython3",
295 | "version": "3.11.5"
296 | },
297 | "nav_menu": {},
298 | "toc": {
299 | "base_numbering": 1,
300 | "nav_menu": {},
301 | "number_sections": true,
302 | "sideBar": true,
303 | "skip_h1_title": false,
304 | "title_cell": "Table of Contents",
305 | "title_sidebar": "Contents",
306 | "toc_cell": false,
307 | "toc_position": {},
308 | "toc_section_display": "block",
309 | "toc_window_display": false
310 | },
311 | "varInspector": {
312 | "cols": {
313 | "lenName": 16,
314 | "lenType": 16,
315 | "lenVar": 40
316 | },
317 | "kernels_config": {
318 | "python": {
319 | "delete_cmd_postfix": "",
320 | "delete_cmd_prefix": "del ",
321 | "library": "var_list.py",
322 | "varRefreshCmd": "print(var_dic_list())"
323 | },
324 | "r": {
325 | "delete_cmd_postfix": ") ",
326 | "delete_cmd_prefix": "rm(",
327 | "library": "var_list.r",
328 | "varRefreshCmd": "cat(var_dic_list()) "
329 | }
330 | },
331 | "types_to_exclude": [
332 | "module",
333 | "function",
334 | "builtin_function_or_method",
335 | "instance",
336 | "_Feature"
337 | ],
338 | "window_display": false
339 | }
340 | },
341 | "nbformat": 4,
342 | "nbformat_minor": 1
343 | }
344 |
--------------------------------------------------------------------------------
/day 2_ Tuesday/assignment/customers.csv:
--------------------------------------------------------------------------------
1 | ,cust_id,first_name_,last_name_,price_count,price_sum,price_mean
2 | 0,1,Max, Mustemann,4,155.96,38.99
3 | 1,2,Ben, Mayer,3,68.97,22.99
4 | 2,3,Sarah, Mueller,4,177.96,44.49
5 | 3,4,Tina, Berger,8,226.92,28.36
6 | 4,5,Donald, T.,9,381.91,42.43
7 | 5,6,Miriam, Faber,2,45.98,22.99
8 | 6,8,Fabian, Engelbert,1,15.99,15.99
9 | 7,9,Hans, Kleber,7,245.93,35.13
10 | 8,10,Brigitte, Jefferson,2,31.98,15.99
11 |
--------------------------------------------------------------------------------
/day 2_ Tuesday/assignment/ex_3.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "bGIGSnHXLvId"
7 | },
8 | "source": [
9 | "# Assignment 3: Loops, Functions, and Data Exploration with Pandas\n",
10 | "\n",
11 | "Indira Sen"
12 | ]
13 | },
14 | {
15 | "cell_type": "markdown",
16 | "metadata": {
17 | "id": "0tfnt0QN-98D"
18 | },
19 | "source": [
20 | "# Ex 1: Quality of Government Dataset (Total: 4.5 points)\n",
21 | "Read in the government dataset directly from \"http://www.qogdata.pol.gu.se/data/qog_std_cs_jan19.csv\"\n",
22 | "\n",
23 | "A. How many rows does this dataset have? (0.5 points)\n",
24 | "\n",
25 | "B. How many columns does this dataset have? (0.5 points)\n",
26 | "\n",
27 | "C. Select the following columns from the dataset:\n",
28 | "\"cname\", \"wdi_pop\", \"wdi_popgr\", \"wdi_gdpcapcur\", \"wdi_gdpcapgr\", \"wdi_area\", \"wdi_broadb\", \"ht_region\" into another dataframe (0.5 points)\n",
29 | "\n",
30 | "D. Rename the columns to: \"country\", \"population\",\"population_growth\", \"gdp_per_capita\", \"gdp_growth\", \"area\", \"internet\", \"region\" (0.5 points)\n",
31 | "\n",
32 | "E. Rename the region codes 1-10 with\n",
33 | "\"Eastern Europe\", \"Latin America\", \"North Africa & Middle East\", \"Sub-Saharan Africa\", \"Western Europe and North America\", \"East Asia\",\"South-East Asia\", \"South Asia\", \"Pacific\", \"Caribbean\" (1 point)\n",
34 | "\n",
35 | "F. What are the mean values for each attribute? (1 point)\n",
36 | "\n",
37 | "G. Which country has the highest population in the region \"Eastern Europe\"? (0.5 points)"
38 | ]
39 | },
40 | {
41 | "cell_type": "markdown",
42 | "metadata": {
43 | "id": "Sg6-DbsGLvBR"
44 | },
45 | "source": []
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": null,
50 | "metadata": {
51 | "id": "yhJWcviy-98G"
52 | },
53 | "outputs": [],
54 | "source": []
55 | },
56 | {
57 | "cell_type": "markdown",
58 | "metadata": {
59 | "id": "Svgbispj-98J"
60 | },
61 | "source": [
62 | "# Ex 2: Book and Movie shop (Total: 10.5 points)"
63 | ]
64 | },
65 | {
66 | "cell_type": "markdown",
67 | "metadata": {
68 | "id": "ZPpYj_nt-98K"
69 | },
70 | "source": [
71 | "For a virtual shop that sells movies and books, we have four tables:\n",
72 | " \n",
73 | " 1. pd_customers: Gives first- and lastname for each customer\n",
74 | " 2. pd_books: Gives the raw price for all books that are being sold\n",
75 | " 3. pd_movies: Gives the raw price for all movies that are being sold\n",
76 | " 4. pd_transactions: Gives the list of all transactions being made (which customer bought which item)\n",
77 | "\n",
78 | "Do the following:\n",
79 | "\n",
80 | "A. Load all 4 datasets in separate dataframes (2 points)\n",
81 | "\n",
82 | "B. Compile a listing of all items (=books and movies) that have been sold in one dataframe\n",
83 | "The dataframe should contain two columns: \"item_name\" and \"price\" (1 point)\n",
84 | "\n",
85 | "C. Join the information on customer names, transactions, and prices in one dataframe (1 point)\n",
86 | "\n",
87 | "D. Compute a table of customers. For all customers give the number of items bought, the sum of these items, and the average price of the item. (2 points)\n",
88 | "\n",
89 | "E. Extend that list such that it also contains customers without purchases (1 point)\n",
90 | "\n",
91 | "F. Round the price mean and the price sum to two digits and export the table to a .csv file (1.5 points)\n",
92 | "\n",
93 | "G. Compute lists of the top 10 bestselling items, both by count and by sum of prices (2 points)\n"
94 | ]
95 | },
96 | {
97 | "cell_type": "code",
98 | "execution_count": null,
99 | "metadata": {
100 | "id": "AOr8rbkk-98K"
101 | },
102 | "outputs": [],
103 | "source": []
104 | }
105 | ],
106 | "metadata": {
107 | "colab": {
108 | "provenance": []
109 | },
110 | "hide_input": false,
111 | "kernelspec": {
112 | "display_name": "Python 3 (ipykernel)",
113 | "language": "python",
114 | "name": "python3"
115 | },
116 | "language_info": {
117 | "codemirror_mode": {
118 | "name": "ipython",
119 | "version": 3
120 | },
121 | "file_extension": ".py",
122 | "mimetype": "text/x-python",
123 | "name": "python",
124 | "nbconvert_exporter": "python",
125 | "pygments_lexer": "ipython3",
126 | "version": "3.11.5"
127 | },
128 | "nav_menu": {},
129 | "toc": {
130 | "base_numbering": 1,
131 | "nav_menu": {},
132 | "number_sections": true,
133 | "sideBar": true,
134 | "skip_h1_title": false,
135 | "title_cell": "Table of Contents",
136 | "title_sidebar": "Contents",
137 | "toc_cell": false,
138 | "toc_position": {},
139 | "toc_section_display": false,
140 | "toc_window_display": false
141 | },
142 | "varInspector": {
143 | "cols": {
144 | "lenName": 16,
145 | "lenType": 16,
146 | "lenVar": 40
147 | },
148 | "kernels_config": {
149 | "python": {
150 | "delete_cmd_postfix": "",
151 | "delete_cmd_prefix": "del ",
152 | "library": "var_list.py",
153 | "varRefreshCmd": "print(var_dic_list())"
154 | },
155 | "r": {
156 | "delete_cmd_postfix": ") ",
157 | "delete_cmd_prefix": "rm(",
158 | "library": "var_list.r",
159 | "varRefreshCmd": "cat(var_dic_list()) "
160 | }
161 | },
162 | "types_to_exclude": [
163 | "module",
164 | "function",
165 | "builtin_function_or_method",
166 | "instance",
167 | "_Feature"
168 | ],
169 | "window_display": false
170 | }
171 | },
172 | "nbformat": 4,
173 | "nbformat_minor": 1
174 | }
175 |
--------------------------------------------------------------------------------
/day 2_ Tuesday/assignment/ex_4.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "VDM62QDIgOyE"
7 | },
8 | "source": [
9 | "# Assignment 5: Data visualization\n",
10 | "Indira Sen"
11 | ]
12 | },
13 | {
14 | "cell_type": "code",
15 | "execution_count": null,
16 | "metadata": {
17 | "id": "LT5rZK_-gOyM"
18 | },
19 | "outputs": [],
20 | "source": [
21 | "import numpy as np\n",
22 | "import matplotlib.pyplot as plt\n",
23 | "%matplotlib inline"
24 | ]
25 | },
26 | {
27 | "cell_type": "markdown",
28 | "metadata": {
29 | "id": "f0U5WmpYgOyO"
30 | },
31 | "source": [
32 | "# Toy data"
33 | ]
34 | },
35 | {
36 | "cell_type": "markdown",
37 | "metadata": {
38 | "id": "Wu2xvrbngOyO"
39 | },
40 | "source": [
41 | "## 1. Create a scatter plot for the following data (2 points)"
42 | ]
43 | },
44 | {
45 | "cell_type": "code",
46 | "execution_count": null,
47 | "metadata": {
48 | "id": "WiynGMw3gOyP"
49 | },
50 | "outputs": [],
51 | "source": [
52 | "age = [32,34,19,33,57,15,62,65,32,17]\n",
53 | "income = [52000,27000,7000,23000,18500,50000,72000,22000,42000,0]"
54 | ]
55 | },
56 | {
57 | "cell_type": "markdown",
58 | "metadata": {
59 | "id": "O69eSsV4gOyQ"
60 | },
61 | "source": [
62 | "## 2. Create a simple line plot with two lines comparing the following measurements (2 points)\n",
63 | "\n"
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": null,
69 | "metadata": {
70 | "id": "HAgZc8osgOyR"
71 | },
72 | "outputs": [],
73 | "source": [
74 | "weather_station_1 = [22,17,18,19,25,26,28,17,15,12]\n",
75 | "weather_station_2 = [24,19,17,18,24,27,29,15,14,10]"
76 | ]
77 | },
78 | {
79 | "cell_type": "markdown",
80 | "metadata": {
81 | "id": "Mnyk81qtgOyR"
82 | },
83 | "source": [
84 | "## 3. Style this plot (1 point)\n",
85 | "The line colors should be red and blue; Add a legend; set the visible area for the y-axis from -5 to 35"
86 | ]
87 | },
88 | {
89 | "cell_type": "code",
90 | "execution_count": null,
91 | "metadata": {
92 | "id": "vmk570wZgOyS"
93 | },
94 | "outputs": [],
95 | "source": []
96 | },
97 | {
98 | "cell_type": "markdown",
99 | "metadata": {
100 | "id": "yL6WShOkgOyT"
101 | },
102 | "source": [
103 | "## 4. Visualize the following election data with a paired bar chart"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": null,
109 | "metadata": {
110 | "id": "uCAM-7hygOyU"
111 | },
112 | "outputs": [],
113 | "source": [
114 | "parties = [\"CDU\",\"SPD\",\"AfD\", \"FDP\", \"DIE LINKE\", \"GRÜNE\", \"CSU\", \"Sonstige\"]\n",
115 | "result_2017 = [26.8,20.5,12.6,10.7,9.2,8.9,6.2,5.0]\n",
116 | "result_2013 = [34.1,25.7,4.7,4.8,8.6,8.4,7.4,6.2]"
117 | ]
118 | },
119 | {
120 | "cell_type": "markdown",
121 | "metadata": {
122 | "id": "gAt1VfCtgOyU"
123 | },
124 | "source": [
125 | "## Create two pie charts for the above election data (2 points)"
126 | ]
127 | },
128 | {
129 | "cell_type": "code",
130 | "execution_count": null,
131 | "metadata": {
132 | "id": "SIT_-LDKgOyV"
133 | },
134 | "outputs": [],
135 | "source": []
136 | },
137 | {
138 | "cell_type": "markdown",
139 | "metadata": {
140 | "id": "u3hmt0EngOyV"
141 | },
142 | "source": [
143 | "# Quality of Government dataset"
144 | ]
145 | },
146 | {
147 | "cell_type": "code",
148 | "execution_count": null,
149 | "metadata": {
150 | "id": "ccVBJbUKgOyV"
151 | },
152 | "outputs": [],
153 | "source": [
154 | "import pandas as pd"
155 | ]
156 | },
157 | {
158 | "cell_type": "code",
159 | "execution_count": null,
160 | "metadata": {
161 | "id": "SgMaL11xgOyV"
162 | },
163 | "outputs": [],
164 | "source": [
165 | "#read the data directly online:\n",
166 | "data = pd.read_csv (\"http://www.qogdata.pol.gu.se/dataarchive/qog_std_cs_jan17.csv\")\n",
167 | "df = data [[\"cname\", \"wdi_pop\", \"wdi_popgr\", \"wdi_gdpcapcur\", \"wdi_gdpcapgr\", \"wdi_area\", \"wdi_broadb\", \"ht_region\"]]\n",
168 | "df.columns = [\"name\", \"population\",\"population_growth\", \"gdp_per_capita\", \"gdp_growth\", \"area\", \"internet\", \"region\"]\n",
169 | "df.region = df.region.replace (range(1,11) , [\"Eastern Europe\", \"Latin America\", \"North Africa & Middle East\", \"Sub-Saharan Africa\", \"Western Europe and North America\", \"East Asia\",\"South-East Asia\", \"South Asia\", \"Pacific\", \"Caribbean\"])"
170 | ]
171 | },
172 | {
173 | "cell_type": "code",
174 | "execution_count": null,
175 | "metadata": {
176 | "id": "Af1a2CsvgOyW"
177 | },
178 | "outputs": [],
179 | "source": [
180 | "# lets pre-compute the population density for each country, we will need it a couple of times\n",
181 | "df [\"population_density\"] = df.population / df.area"
182 | ]
183 | },
184 | {
185 | "cell_type": "markdown",
186 | "metadata": {
187 | "id": "gya7IVaFgOyW"
188 | },
189 | "source": [
190 | "## 5. Plot a bar chart of the population density in each country. Sort the bars in descending order of the population density (2 points)\n",
191 | "\n"
192 | ]
193 | },
194 | {
195 | "cell_type": "code",
196 | "execution_count": null,
197 | "metadata": {
198 | "id": "sUx3nLIVgOyX"
199 | },
200 | "outputs": [],
201 | "source": []
202 | },
203 | {
204 | "cell_type": "markdown",
205 | "metadata": {
206 | "id": "u_Em-ISogOyX"
207 | },
208 | "source": [
209 | "## 6. Plot a bar chart for the population in each country. Test the effect of using a logarithmic scale on the y-axis (2 points)"
210 | ]
211 | },
212 | {
213 | "cell_type": "code",
214 | "execution_count": null,
215 | "metadata": {
216 | "id": "IwK2K9EvgOyX"
217 | },
218 | "outputs": [],
219 | "source": []
220 | },
221 | {
222 | "cell_type": "markdown",
223 | "metadata": {
224 | "id": "F85p9mX9gOyX"
225 | },
226 | "source": [
227 | "## 7. Plot a histogram for the attribute 'population_growth' (1 point)"
228 | ]
229 | },
230 | {
231 | "cell_type": "code",
232 | "execution_count": null,
233 | "metadata": {
234 | "id": "aBY3C9t5gOyX"
235 | },
236 | "outputs": [],
237 | "source": []
238 | },
239 | {
240 | "cell_type": "markdown",
241 | "metadata": {
242 | "id": "ccrLEJzFgOyY"
243 | },
244 | "source": [
245 | "## 8. Compute the average (per country) population_growth and gdp_per_capita for each region. Plot these in a scatter plot against each other (2 points)"
246 | ]
247 | },
248 | {
249 | "cell_type": "code",
250 | "execution_count": null,
251 | "metadata": {
252 | "id": "xjVXcg8LgOyY"
253 | },
254 | "outputs": [],
255 | "source": []
256 | },
257 | {
258 | "cell_type": "markdown",
259 | "metadata": {
260 | "id": "8jHJOhgygOyY"
261 | },
262 | "source": [
263 | "## 9. Bonus: Add to the last plot a label (region name) for each region (1 point)"
264 | ]
265 | },
266 | {
267 | "cell_type": "code",
268 | "execution_count": null,
269 | "metadata": {
270 | "id": "f0s_TpJBgOyZ"
271 | },
272 | "outputs": [],
273 | "source": []
274 | }
275 | ],
276 | "metadata": {
277 | "colab": {
278 | "provenance": []
279 | },
280 | "kernelspec": {
281 | "display_name": "Python 3 (ipykernel)",
282 | "language": "python",
283 | "name": "python3"
284 | },
285 | "language_info": {
286 | "codemirror_mode": {
287 | "name": "ipython",
288 | "version": 3
289 | },
290 | "file_extension": ".py",
291 | "mimetype": "text/x-python",
292 | "name": "python",
293 | "nbconvert_exporter": "python",
294 | "pygments_lexer": "ipython3",
295 | "version": "3.11.5"
296 | },
297 | "nav_menu": {},
298 | "toc": {
299 | "base_numbering": 1,
300 | "nav_menu": {},
301 | "number_sections": true,
302 | "sideBar": true,
303 | "skip_h1_title": false,
304 | "title_cell": "Table of Contents",
305 | "title_sidebar": "Contents",
306 | "toc_cell": false,
307 | "toc_position": {},
308 | "toc_section_display": "block",
309 | "toc_window_display": false
310 | },
311 | "varInspector": {
312 | "cols": {
313 | "lenName": 16,
314 | "lenType": 16,
315 | "lenVar": 40
316 | },
317 | "kernels_config": {
318 | "python": {
319 | "delete_cmd_postfix": "",
320 | "delete_cmd_prefix": "del ",
321 | "library": "var_list.py",
322 | "varRefreshCmd": "print(var_dic_list())"
323 | },
324 | "r": {
325 | "delete_cmd_postfix": ") ",
326 | "delete_cmd_prefix": "rm(",
327 | "library": "var_list.r",
328 | "varRefreshCmd": "cat(var_dic_list()) "
329 | }
330 | },
331 | "types_to_exclude": [
332 | "module",
333 | "function",
334 | "builtin_function_or_method",
335 | "instance",
336 | "_Feature"
337 | ],
338 | "window_display": false
339 | }
340 | },
341 | "nbformat": 4,
342 | "nbformat_minor": 1
343 | }
344 |
--------------------------------------------------------------------------------
/day 2_ Tuesday/assignment/pd_books.csv:
--------------------------------------------------------------------------------
1 | book,price
2 | Book 1,9.99
3 | Book 2,8.99
4 | Book 3,29.99
5 | Book 4,8.49
6 | Book 5,15.99
7 | Book 6,12.19
8 | Book 7,13.99
9 | Book 8,49.99
10 | Book 9,125.99
11 | Book 10,8.99
12 |
--------------------------------------------------------------------------------
/day 2_ Tuesday/assignment/pd_customers.csv:
--------------------------------------------------------------------------------
1 | cust_id,first_name,last_name
2 | 1,Max, Mustemann
3 | 2,Ben, Mayer
4 | 3,Sarah, Mueller
5 | 4,Tina, Berger
6 | 5,Donald, T.
7 | 6,Miriam, Faber
8 | 7,Thomas, Hase
9 | 8,Fabian, Engelbert
10 | 9,Hans, Kleber
11 | 10,Brigitte, Jefferson
12 |
--------------------------------------------------------------------------------
/day 2_ Tuesday/assignment/pd_movies.csv:
--------------------------------------------------------------------------------
1 | movie,price
2 | Movie 1,15.99
3 | Movie 2,22.99
4 | Movie 3,15.99
5 | Movie 4,14.49
6 | Movie 5,3.99
7 | Movie 6,2.19
8 | Movie 7,11.99
9 | Movie 8,31.99
10 | Movie 9,35.99
11 | Movie 10,1.99
12 |
--------------------------------------------------------------------------------
/day 2_ Tuesday/assignment/pd_transactions.csv:
--------------------------------------------------------------------------------
1 | cust_id,item
2 | 1,Book 1
3 | 1,Movie 1
4 | 1,Movie 5
5 | 1,Book 9
6 | 2,Book 1
7 | 2,Book 8
8 | 2,Book 10
9 | 3,Movie 1
10 | 3,Movie 5
11 | 3,Movie 8
12 | 3,Book 9
13 | 4,Book 10
14 | 4,Book 7
15 | 4,Movie 8
16 | 4,Movie 3
17 | 4,Book 9
18 | 4,Book 1
19 | 4,Movie 1
20 | 4,Movie 5
21 | 5,Book 9
22 | 5,Book 1
23 | 5,Book 8
24 | 5,Book 10
25 | 5,Movie 1
26 | 5,Movie 5
27 | 5,Movie 8
28 | 5,Book 9
29 | 5,Book 10
30 | 6,Book 7
31 | 6,Movie 8
32 | 8,Movie 3
33 | 9,Book 8
34 | 9,Book 10
35 | 9,Movie 1
36 | 9,Movie 5
37 | 9,Movie 8
38 | 9,Book 9
39 | 9,Book 10
40 | 10,Movie 2
41 | 10,Book 2
--------------------------------------------------------------------------------
/day 2_ Tuesday/notebooks/21_data_exploration_ex_1.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 |
3 | # ####### step 1
4 | adult_df = pd.read_csv("data/adult.csv", na_values="?")
5 |
6 | # ####### step 2
7 | # get a subset of dataframe
8 | adult_df = adult_df[["age", "sex", "education", "hours-per-week", "capital-gain"]]
9 |
10 | # ####### step 3
11 | # rename a column
12 | adult_df.rename(columns={"capital-gain" : "capital_gain"}, inplace=True)
13 |
14 | print("####### step 4")
15 | print("Column names:", adult_df.columns.values)
16 |
17 | print("####### step 5")
18 | print("Number of different 'education' values:", len(adult_df["education"].unique()))
19 |
20 | print("####### step 6")
21 | print("Mean 'working time per week':", adult_df["hours-per-week"].mean())
22 |
23 | print("####### step 7")
24 | # adult_df["capital_gain"].max()
25 | print("Max capital gain:", adult_df.capital_gain.max())
--------------------------------------------------------------------------------
/day 2_ Tuesday/notebooks/21_data_exploration_ex_2.py:
--------------------------------------------------------------------------------
1 | # ####### step 2
2 | bachelors = adult_df[adult_df["education"] == "Bachelors"]
3 |
4 | print("####### step 3")
5 | print("Number of persons with a Bachelor degree as their highest degree:", len(bachelors))
6 |
7 | print("####### step 4")
8 | print("Sum of their capital_gain: ", bachelors.capital_gain.sum())
9 |
10 | print("####### step 5")
11 | print(bachelors.sex.value_counts())
12 | print('-------OR-------')
13 | print("Female: ", len(bachelors[bachelors["sex"] == "Female"]))
14 | print("Male: ", len(bachelors[bachelors["sex"] == "Male"]))
15 |
16 | # ####### step 6
17 | bachelors = bachelors.sort_values(["capital_gain", "age"], ascending=False)
18 |
19 | print("####### step 7")
20 | bachelors[(bachelors["age"] >= 20) & (bachelors["age"] <= 40)].head(10)
--------------------------------------------------------------------------------
/day 2_ Tuesday/notebooks/21_functions_ex_1.py:
--------------------------------------------------------------------------------
1 | def greet(first_name, last_name):
2 | # print("Hello {} {}".format(first_name, last_name))
3 | # print("I wish you a very nice day.")
4 |
5 | print("Hello {} {},\nI wish you a very nice day.\n".format(first_name, last_name))
6 |
7 | people = [["Adriana", "Schmidt"], ["Billy", "Müller"], ["Caroline", "Schneider"]]
8 | for first_name, last_name in people:
9 | greet(first_name, last_name)
10 |
11 | # for person_data in people:
12 | # greet(person_data[0], person_data[1])
--------------------------------------------------------------------------------
/day 2_ Tuesday/notebooks/21_functions_ex_2.py:
--------------------------------------------------------------------------------
1 | def calculate_sum(number_1, number_2):
2 | sum_ = number_1 + number_2
3 | return sum_
4 |
5 | number_lists = [[1, 1], [1, 2], [20, 10]]
6 | for n_1, n_2 in number_lists:
7 | output = calculate_sum(n_1, n_2)
8 | print("{} + {} = {}".format(n_1, n_2, output))
--------------------------------------------------------------------------------
/day 2_ Tuesday/notebooks/21_functions_ex_3.py:
--------------------------------------------------------------------------------
1 | def describe_person(name, favourite_color="green", favourite_game=None):
2 | print("Hi, this is {}.".format(name.title()))
3 |
4 | if favourite_color:
5 | print("My favourite color is {}.".format(favourite_color))
6 | else:
7 | print("I have no favourite color.")
8 |
9 | if favourite_game:
10 | print("My favourite game is {}.".format(favourite_game))
11 | else:
12 | print("I have no favourite game.")
13 | print("\n")
14 |
15 | describe_person("ken")
16 | describe_person("ADELE", favourite_color="black", favourite_game="backgammon")
17 | describe_person("Brian", favourite_color=None, favourite_game="chess")
18 | describe_person("Brian", favourite_game="chess")
--------------------------------------------------------------------------------
/day 2_ Tuesday/notebooks/23_data_processing_ex_1.py:
--------------------------------------------------------------------------------
1 | """
2 | Ex 1
3 |
4 | """
5 |
6 | print("A Use Census data")
7 |
8 |
9 | df = pd.read_csv ("data/adult.csv", na_values="?")
10 | df.head()
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/day 2_ Tuesday/notebooks/23_data_processing_ex_2.py:
--------------------------------------------------------------------------------
1 | print("A.1 Show for each combination of sex and race, how many instances(people) are contained in the dataset")
2 |
3 |
4 | df.groupby(["sex", "race"]).size().unstack()
--------------------------------------------------------------------------------
/day 2_ Tuesday/notebooks/23_data_processing_ex_3.py:
--------------------------------------------------------------------------------
1 | print("A.2 What is the mean age of men and women in this dataset?")
2 |
3 |
4 | g = df.groupby("sex")
5 | g.mean()["age"]
6 |
7 |
--------------------------------------------------------------------------------
/day 2_ Tuesday/notebooks/23_data_processing_ex_4.py:
--------------------------------------------------------------------------------
1 | print("A.3 Show for each combination of marital-Status and race how many males/females over 40 years have a bachelor degree as their highest degree?")
2 |
3 |
4 | df2 = df[(df["age"] > 40) & (df["education"] =="Bachelors")]
5 | df2.groupby(["marital-status","race","sex"]).size().unstack().fillna(0)
6 |
--------------------------------------------------------------------------------
/day 2_ Tuesday/notebooks/data/weather.csv:
--------------------------------------------------------------------------------
1 | time,temperature,status
2 | 2017-08-31 11:00:00,15,rainy
3 | 2017-08-31 23:00:00,8,rainy
4 | 2017-09-01 11:00:00,19,rainy
5 | 2017-09-01 23:00:00,9,rainy
6 | 2017-09-02 11:00:00,21,cloudy
7 | 2017-09-03 11:00:00,21,cloudy
8 | 2017-09-04 11:00:00,22,sunny
9 | 2017-09-04 23:00:00,12,sunny
10 | 2017-09-05 11:00:00,24,sunny
11 | 2017-09-05 23:00:00,13,sunny
--------------------------------------------------------------------------------
/eKOMEX/Introduction to Python Schedule (EKOMEX 2024).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Indiiigo/Intro_to_python/3035764946d2c52d3d86d9e1db7ece284b0f59ee/eKOMEX/Introduction to Python Schedule (EKOMEX 2024).pdf
--------------------------------------------------------------------------------
/eKOMEX/day 1_ Thursday/assignment/ex_1.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "SN-mb9j3Yc1X"
7 | },
8 | "source": [
9 | "# Exercise: Introduction to Python & Basic Concepts"
10 | ]
11 | },
12 | {
13 | "cell_type": "markdown",
14 | "metadata": {
15 | "id": "QjcesK4dZSw4"
16 | },
17 | "source": [
18 | "## Ex 1\n",
19 | "\n",
20 | "This exercise covers variables.\n",
21 | "\n",
22 | "1. Use some of the arithmetic operations you want and do some calculations.\n",
23 | " 1. Optional: By using `.format()` method to print outputs in such a format \"1+1=2\"\n",
24 | "\n",
25 | "2. Define variables a = 16, b = 4 and c = 2.\n",
26 | " 1. Print result of a/b*c+c\n",
27 | " 2. Do the same calculation but force multiplication to be first and then sum and finally division (by using parentheses)\n",
28 | "\n",
29 | "3. Define a sentence and print it's length in a sentence in format of \"The length of 'sentence' is 8.\" (use `.format()` method)"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": null,
35 | "metadata": {},
36 | "outputs": [],
37 | "source": []
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "metadata": {
42 | "id": "SeX48MfjYc1Z"
43 | },
44 | "source": [
45 | "## Ex 2\n",
46 | "This exercise covers variables and lists"
47 | ]
48 | },
49 | {
50 | "cell_type": "markdown",
51 | "metadata": {
52 | "id": "0SF9mdqjYc1a"
53 | },
54 | "source": [
55 | "1. Make a list of names that includes at least five people.\n",
56 | "2. Write an if test that prints a message about the room being crowded, if there are more than four people in your list.\n",
57 | "3. Modify your list so that there are only two people in it. Use one of the methods for accessing items from the list.\n",
58 | "4. Add some names to your list, so that there are at least seven people in the list. Use one of the methods for appending people from the list, don't just redefine the list."
59 | ]
60 | },
61 | {
62 | "cell_type": "code",
63 | "execution_count": null,
64 | "metadata": {},
65 | "outputs": [],
66 | "source": []
67 | },
68 | {
69 | "cell_type": "markdown",
70 | "metadata": {
71 | "id": "72ZcTAGWYc1b"
72 | },
73 | "source": [
74 | "## Ex 3\n",
75 | "This exercise covers variables and lists"
76 | ]
77 | },
78 | {
79 | "cell_type": "markdown",
80 | "metadata": {
81 | "id": "-7-5-5waYc1b"
82 | },
83 | "source": [
84 | "1. Create a list of lists where each sub list holds the arguments for the function bellow. Loop this list of lists and first check if the length of inner list is not 2, then print an error message \"Length of numbers must be 2!\". Otherwise call the function and print the result of the function.\n",
85 | "\n",
86 | "2. Test your code by this list of lists: `number_lists = [[1, 1], [\"five\", 3], [5, \"three\"], [2, 2, 2], [5.5, 8]]`\n"
87 | ]
88 | },
89 | {
90 | "cell_type": "code",
91 | "execution_count": 1,
92 | "metadata": {},
93 | "outputs": [],
94 | "source": [
95 | "#The function is defined here \n",
96 | "def function(a,b): \n",
97 | " print(f\"Function successfully called! The input was {a} and {b}\")"
98 | ]
99 | },
100 | {
101 | "cell_type": "code",
102 | "execution_count": null,
103 | "metadata": {},
104 | "outputs": [],
105 | "source": []
106 | },
107 | {
108 | "cell_type": "code",
109 | "execution_count": null,
110 | "metadata": {
111 | "id": "9EkA-bAZ7EC-"
112 | },
113 | "outputs": [],
114 | "source": []
115 | }
116 | ],
117 | "metadata": {
118 | "colab": {
119 | "provenance": []
120 | },
121 | "kernelspec": {
122 | "display_name": "Python 3 (ipykernel)",
123 | "language": "python",
124 | "name": "python3"
125 | },
126 | "language_info": {
127 | "codemirror_mode": {
128 | "name": "ipython",
129 | "version": 3
130 | },
131 | "file_extension": ".py",
132 | "mimetype": "text/x-python",
133 | "name": "python",
134 | "nbconvert_exporter": "python",
135 | "pygments_lexer": "ipython3",
136 | "version": "3.11.4"
137 | },
138 | "toc": {
139 | "base_numbering": 1,
140 | "nav_menu": {},
141 | "number_sections": false,
142 | "sideBar": false,
143 | "skip_h1_title": true,
144 | "title_cell": "Table of Contents",
145 | "title_sidebar": "Contents",
146 | "toc_cell": false,
147 | "toc_position": {},
148 | "toc_section_display": false,
149 | "toc_window_display": false
150 | }
151 | },
152 | "nbformat": 4,
153 | "nbformat_minor": 4
154 | }
155 |
--------------------------------------------------------------------------------
/eKOMEX/day 1_ Thursday/assignment/ex_1_answers.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "SN-mb9j3Yc1X"
7 | },
8 | "source": [
9 | "# Exercise: Introduction to Python & Basic Concepts"
10 | ]
11 | },
12 | {
13 | "cell_type": "markdown",
14 | "metadata": {
15 | "id": "QjcesK4dZSw4"
16 | },
17 | "source": [
18 | "## Ex 1\n",
19 | "\n",
20 | "This exercise covers variables.\n",
21 | "\n",
22 | "1. Use some of the arithmetic operations you want and do some calculations.\n",
23 | " 1. Optional: By using `.format()` method to print outputs in such a format \"1+1=2\"\n",
24 | "\n",
25 | "2. Define variables a = 16, b = 4 and c = 2.\n",
26 | " 1. Print result of a/b*c+c\n",
27 | " 2. Do the same calculation but force multiplication to be first and then sum and finally division (by using parentheses)\n",
28 | "\n",
29 | "3. Define a sentence and print it's length in a sentence in format of \"The length of 'sentence' is 8.\" (use `.format()` method)"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": 1,
35 | "metadata": {
36 | "colab": {
37 | "base_uri": "https://localhost:8080/"
38 | },
39 | "executionInfo": {
40 | "elapsed": 7,
41 | "status": "ok",
42 | "timestamp": 1696845936792,
43 | "user": {
44 | "displayName": "Indira Sen",
45 | "userId": "11191672663586892835"
46 | },
47 | "user_tz": -120
48 | },
49 | "id": "VscuYWW0ZWlM",
50 | "outputId": "dc77e4cd-485a-4a44-d3d7-ce1df88483b7"
51 | },
52 | "outputs": [
53 | {
54 | "name": "stdout",
55 | "output_type": "stream",
56 | "text": [
57 | "######## Part 1:\n",
58 | "1+1=2\n",
59 | "5-1=4\n",
60 | "6*3=18\n",
61 | "6/3=2.0\n",
62 | "5//3=1\n",
63 | "5%3=2\n",
64 | "2**3=8\n",
65 | "######## Part 2:\n",
66 | "a/b*c+c=10.0\n",
67 | "a/((b*c)+c)=1.6\n",
68 | "######## Part 3:\n",
69 | "The length of 'Define a sentence and print it's length.' is 40.\n"
70 | ]
71 | }
72 | ],
73 | "source": [
74 | "print(\"######## Part 1:\")\n",
75 | "#Use some of the arithmetic operations you want and do some calculations.\n",
76 | "result = 1+1\n",
77 | "print(\"1+1={}\".format(result))\n",
78 | "result = 5-1\n",
79 | "print(\"5-1={}\".format(result))\n",
80 | "result = 6*3\n",
81 | "print(\"6*3={}\".format(result))\n",
82 | "result = 6/3\n",
83 | "print(\"6/3={}\".format(result))\n",
84 | "result = 5//3\n",
85 | "print(\"5//3={}\".format(result))\n",
86 | "result = 5%3\n",
87 | "print(\"5%3={}\".format(result))\n",
88 | "result = 2**3\n",
89 | "print(\"2**3={}\".format(result))\n",
90 | "\n",
91 | "print(\"######## Part 2:\")\n",
92 | "# Define variables a = 16, b = 4 and c = 2.\n",
93 | "a = 16\n",
94 | "b = 4\n",
95 | "c = 2\n",
96 | "\n",
97 | "# Print result of a/b*c+c\n",
98 | "result = a/b*c+c\n",
99 | "print(\"a/b*c+c={}\".format(result))\n",
100 | "\n",
101 | "# Do the same calculation but force multiplication to be first and then sumd and finally division (by using parentheses)\n",
102 | "result = a/((b*c)+c)\n",
103 | "print(\"a/((b*c)+c)={}\".format(result))\n",
104 | "\n",
105 | "print(\"######## Part 3:\")\n",
106 | "# Define a sentence and print it's length.\n",
107 | "sent = \"Define a sentence and print it's length.\"\n",
108 | "print(\"The length of '{}' is {}.\".format(sent, len(sent)))"
109 | ]
110 | },
111 | {
112 | "cell_type": "markdown",
113 | "metadata": {
114 | "id": "SeX48MfjYc1Z"
115 | },
116 | "source": [
117 | "## Ex 2\n",
118 | "This exercise covers variables and lists"
119 | ]
120 | },
121 | {
122 | "cell_type": "markdown",
123 | "metadata": {
124 | "id": "0SF9mdqjYc1a"
125 | },
126 | "source": [
127 | "1. Make a list of names that includes at least five people.\n",
128 | "2. Write an if test that prints a message about the room being crowded, if there are more than four people in your list.\n",
129 | "3. Modify your list so that there are only two people in it. Use one of the methods for removing people from the list, don't just redefine the list.\n",
130 | "4. Add some names to your list, so that there are at least seven people in the list. Use one of the methods for appending people from the list, don't just redefine the list."
131 | ]
132 | },
133 | {
134 | "cell_type": "code",
135 | "execution_count": 1,
136 | "metadata": {
137 | "colab": {
138 | "base_uri": "https://localhost:8080/"
139 | },
140 | "executionInfo": {
141 | "elapsed": 264,
142 | "status": "ok",
143 | "timestamp": 1696846043604,
144 | "user": {
145 | "displayName": "Indira Sen",
146 | "userId": "11191672663586892835"
147 | },
148 | "user_tz": -120
149 | },
150 | "id": "t4SnJYWHYc1a",
151 | "outputId": "50561fcb-a29f-4872-9c4f-61e126a64a6f"
152 | },
153 | "outputs": [
154 | {
155 | "name": "stdout",
156 | "output_type": "stream",
157 | "text": [
158 | "####### step 1\n",
159 | "['adele', 'ken', 'cody', 'caroline', 'tiana']\n",
160 | "####### step 2\n",
161 | "The room is crowded, there are 5 people.\n",
162 | "####### step 3\n",
163 | "['adele', 'tiana']\n",
164 | "####### step 4\n"
165 | ]
166 | }
167 | ],
168 | "source": [
169 | "print(\"####### step 1\")\n",
170 | "# Make a list of names that includes at least five people.\n",
171 | "people = [\"adele\", \"ken\", \"cody\", \"caroline\", \"tiana\"]\n",
172 | "print(people)\n",
173 | "\n",
174 | "print(\"####### step 2\")\n",
175 | "# Write an if test that prints a message about the room being crowded, if there are more than four people in your list.\n",
176 | "if len(people) >= 4:\n",
177 | " print(\"The room is crowded, there are {} people.\".format(len(people)))\n",
178 | "\n",
179 | "print(\"####### step 3\")\n",
180 | "# Modify your list so that there are only two people in it.\n",
181 | "people.remove(\"cody\")\n",
182 | "people.remove(\"caroline\")\n",
183 | "people.remove(\"ken\")\n",
184 | "print(people)\n",
185 | "\n",
186 | "print(\"####### step 4\")\n",
187 | "# Add some names to your list, so that there are at least seven people in the list.\n",
188 | "people.append(\"cody\")\n",
189 | "people.append(\"caroline\")\n",
190 | "people.append(\"adriana\")\n",
191 | "people.append(\"billy\")"
192 | ]
193 | },
194 | {
195 | "cell_type": "markdown",
196 | "metadata": {
197 | "id": "72ZcTAGWYc1b"
198 | },
199 | "source": [
200 | "## Ex 3\n",
201 | "This exercise covers variables and lists"
202 | ]
203 | },
204 | {
205 | "cell_type": "markdown",
206 | "metadata": {
207 | "id": "-7-5-5waYc1b"
208 | },
209 | "source": [
210 | "1. Create a list of lists where each sub list holds the arguments for the function. Loop this list of lists and first check if the length of inner list is not 2, then print an error message \"Length of numbers must be 2!\" and continue to the next iteration (use the `continue` statement). Otherwise call the function and print the result of the function.\n",
211 | "\n",
212 | "2. Test your code by this list of lists: `number_lists = [[1, 1], [\"five\", 3], [5, \"three\"], [2, 2, 2], [5.5, 8]]`\n",
213 | "\n",
214 | "3. Replace `continue` statement with `break` statement and run your code again. Could you notice the difference?"
215 | ]
216 | },
217 | {
218 | "cell_type": "code",
219 | "execution_count": 4,
220 | "metadata": {
221 | "colab": {
222 | "base_uri": "https://localhost:8080/"
223 | },
224 | "executionInfo": {
225 | "elapsed": 236,
226 | "status": "ok",
227 | "timestamp": 1696846318095,
228 | "user": {
229 | "displayName": "Indira Sen",
230 | "userId": "11191672663586892835"
231 | },
232 | "user_tz": -120
233 | },
234 | "id": "BRivZfxYYc1b",
235 | "outputId": "98fde862-86c0-4658-b4c5-46d781fd3fcd"
236 | },
237 | "outputs": [
238 | {
239 | "name": "stdout",
240 | "output_type": "stream",
241 | "text": [
242 | "1 1 : 1\n",
243 | "Invalid input: five\n",
244 | "five 3 : 0\n",
245 | "Invalid input: three\n",
246 | "5 three : 0\n",
247 | "Length of numbers must be 2!\n",
248 | "5.5 8 : 44.0\n"
249 | ]
250 | }
251 | ],
252 | "source": [
253 | "number_lists = [[1, 1], [\"five\", 3], [5, \"three\"], [2, 2, 2], [5.5, 8]]\n",
254 | "for numbers in number_lists:\n",
255 | " if len(numbers) != 2:\n",
256 | " print(\"Length of numbers must be 2!\")\n",
257 | " continue\n",
258 | " else:\n",
259 | " result = 0\n",
260 | " # check type of first number, it must be int or float\n",
261 | " n1 = numbers[0]\n",
262 | " n2 = numbers[1]\n",
263 | " if type(n1) != int and type(n1) != float:\n",
264 | " print(\"Invalid input: {}\".format(n1))\n",
265 | " # check type of second number, it must be int or float\n",
266 | " elif type(n2) != int and type(n2) != float:\n",
267 | " print(\"Invalid input: {}\".format(n2))\n",
268 | " else:\n",
269 | " # do the calculation and return the result\n",
270 | " result = n1 * n2\n",
271 | "\n",
272 | " print(numbers[0], numbers[1], \":\", result)"
273 | ]
274 | },
275 | {
276 | "cell_type": "code",
277 | "execution_count": 5,
278 | "metadata": {
279 | "colab": {
280 | "base_uri": "https://localhost:8080/"
281 | },
282 | "executionInfo": {
283 | "elapsed": 257,
284 | "status": "ok",
285 | "timestamp": 1696846332965,
286 | "user": {
287 | "displayName": "Indira Sen",
288 | "userId": "11191672663586892835"
289 | },
290 | "user_tz": -120
291 | },
292 | "id": "wPiWEzm1Yc1c",
293 | "outputId": "a6cbc065-a6d3-4272-a06c-acd4392a4b89"
294 | },
295 | "outputs": [
296 | {
297 | "name": "stdout",
298 | "output_type": "stream",
299 | "text": [
300 | "1 1 : 1\n",
301 | "Invalid input: five\n",
302 | "five 3 : 0\n",
303 | "Invalid input: three\n",
304 | "5 three : 0\n",
305 | "Length of numbers must be 2!\n"
306 | ]
307 | }
308 | ],
309 | "source": [
310 | "number_lists = [[1, 1], [\"five\", 3], [5, \"three\"], [2, 2, 2], [5.5, 8]]\n",
311 | "for numbers in number_lists:\n",
312 | " if len(numbers) != 2:\n",
313 | " print(\"Length of numbers must be 2!\")\n",
314 | " break\n",
315 | " else:\n",
316 | " result = 0\n",
317 | " # check type of first number, it must be int or float\n",
318 | " n1 = numbers[0]\n",
319 | " n2 = numbers[1]\n",
320 | " if type(n1) != int and type(n1) != float:\n",
321 | " print(\"Invalid input: {}\".format(n1))\n",
322 | " # check type of second number, it must be int or float\n",
323 | " elif type(n2) != int and type(n2) != float:\n",
324 | " print(\"Invalid input: {}\".format(n2))\n",
325 | " else:\n",
326 | " # do the calculation and return the result\n",
327 | " result = n1 * n2\n",
328 | "\n",
329 | " print(numbers[0], numbers[1], \":\", result)"
330 | ]
331 | },
332 | {
333 | "cell_type": "code",
334 | "execution_count": null,
335 | "metadata": {
336 | "id": "9EkA-bAZ7EC-"
337 | },
338 | "outputs": [],
339 | "source": []
340 | }
341 | ],
342 | "metadata": {
343 | "colab": {
344 | "provenance": []
345 | },
346 | "kernelspec": {
347 | "display_name": "Python 3 (ipykernel)",
348 | "language": "python",
349 | "name": "python3"
350 | },
351 | "language_info": {
352 | "codemirror_mode": {
353 | "name": "ipython",
354 | "version": 3
355 | },
356 | "file_extension": ".py",
357 | "mimetype": "text/x-python",
358 | "name": "python",
359 | "nbconvert_exporter": "python",
360 | "pygments_lexer": "ipython3",
361 | "version": "3.10.7"
362 | },
363 | "toc": {
364 | "base_numbering": 1,
365 | "nav_menu": {},
366 | "number_sections": false,
367 | "sideBar": false,
368 | "skip_h1_title": true,
369 | "title_cell": "Table of Contents",
370 | "title_sidebar": "Contents",
371 | "toc_cell": false,
372 | "toc_position": {},
373 | "toc_section_display": false,
374 | "toc_window_display": false
375 | }
376 | },
377 | "nbformat": 4,
378 | "nbformat_minor": 4
379 | }
380 |
--------------------------------------------------------------------------------
/eKOMEX/day 1_ Thursday/notebooks/11_var_string_num_ex1_1.py:
--------------------------------------------------------------------------------
1 | # Store a message in a variable
2 | msg = "Hey"
3 | # Print that message
4 | print(msg)
5 |
6 | # Store a new message in the same variable
7 | msg = "How are you?"
8 | # Print that new message
9 | print(msg)
--------------------------------------------------------------------------------
/eKOMEX/day 1_ Thursday/notebooks/11_var_string_num_ex1_2.py:
--------------------------------------------------------------------------------
1 | print("####### Part 1:")
2 | # Store the quote in a variable.
3 | quote = "One of my most productive days was throwing away 1000 lines of code"
4 | # Store the full name of the person in another variable.
5 | person = "Ken Thompson"
6 |
7 | # Print a sentence in such format "X once said, 'quote comes here'."
8 | sentence = "{} once said, '{}'.".format(person, quote)
9 | print(sentence)
10 |
11 | print("####### Part 2:")
12 | # Store a first name and a last name, in lowercase, in 2 different variables.
13 | first_name = "name"
14 | last_name = "surname"
15 | # Using that variables store the full name in another variable (concatenation)
16 | full_name = first_name + " " + last_name
17 | # full_name = "{} {}".format(first_name, last_name)
18 |
19 | # Print the full name in lowercase, Titlecase, and UPPERCASE.
20 | print(full_name)
21 | print(full_name.lower())
22 | print(full_name.title())
23 | print(full_name.upper())
--------------------------------------------------------------------------------
/eKOMEX/day 1_ Thursday/notebooks/12_lists_tuples-1_ex1_1.py:
--------------------------------------------------------------------------------
1 | #Exercises
2 | """
3 |
4 | First Neat List
5 |
6 | Store the values 'python', 'c', and 'java' in a list. Print a statement about each of these values,
7 | using their position in the list.
8 | Your statement could simply be, 'A nice programming language is value.'
9 |
10 | """
11 |
12 |
13 | languages = ['python', 'c', 'java']
14 |
15 | print("A nice programming language is " + languages[0])
16 | print("A nice programming language is " + languages[1])
17 | print("A nice programming language is {}".format(languages[2]))
18 |
19 |
20 | print("\n")
21 |
22 |
23 | """
24 |
25 | Your First List
26 |
27 | Think of something you can store in a list. Make a list with three or four items,
28 | and then print a message that includes at least one item from your list.
29 | Your sentence could be as simple as, "One item in my list is a ____."
30 |
31 | """
32 |
33 | my_list = [3, 'my CD', 'Kessler', 2.5]
34 |
35 | print("The thing that I cannot live without is {}.".format(my_list[1]))
36 |
--------------------------------------------------------------------------------
/eKOMEX/day 1_ Thursday/notebooks/12_lists_tuples-1_ex1_2.py:
--------------------------------------------------------------------------------
1 | #Exercises
2 | """
3 |
4 | First Neat List - Loop
5 |
6 | Repeat First Neat List, but this time use a loop to print out your statements.
7 | Make sure you are writing the same sentence for all values in your list.
8 | Loops are not effective when you are trying to generate different output for each value in your list.
9 |
10 | """
11 | languages = ['python', 'c', 'java']
12 |
13 |
14 | for language in languages:
15 | print("A nice programming language is " + language)
16 |
17 |
18 | print("\n")
19 |
20 |
21 |
22 | """
23 |
24 | Your First List - Loop
25 |
26 | Repeat Your First List, but this time use a loop to print out your message for each item in your list.
27 | Again, if you came up with different messages for each value in your list, decide on one message to
28 | repeat for each value in your list.
29 |
30 | """
31 |
32 | my_list = [3, 'my CD', 'Kessler', 2.5]
33 |
34 | for thing in my_list:
35 | print("The thing that I cannot live without is {}.".format(thing))
36 |
37 |
--------------------------------------------------------------------------------
/eKOMEX/day 1_ Thursday/notebooks/12_lists_tuples-2_ex1_1.py:
--------------------------------------------------------------------------------
1 | """
2 | Working List
3 |
4 | Make a list that includes four careers, such as 'programmer' and 'truck driver'.
5 | """
6 | print("Part 1")
7 | careers = ['doctor', 'scientist', 'historian', 'teacher']
8 |
9 | print("\nUse the list.index() function to find the index of one career in your list.")
10 |
11 | print(careers.index('historian'))
12 |
13 | print("\nUse the in function to show that this career is in your list.")
14 |
15 | print('historian' in careers)
16 |
17 | print("\nUse the append() function to add a new career to your list.")
18 |
19 | careers.append('politician')
20 | print(careers)
21 |
22 | print("\nUse the insert() function to add a new career at the beginning of the list.")
23 |
24 | careers.insert(0, 'archeologist')
25 | print(careers)
26 | print("\n")
27 |
28 | """
29 | Ordered Working List
30 | """
31 |
32 | print("Start with the list you created in Working List.")
33 |
34 |
35 |
36 | print("\nYou are going to print out the list in a number of different orders.")
37 | print("Each time you print the list, use a for loop rather than printing the raw list.")
38 | print("Print a message each time telling us what order we should see the list in.")
39 |
40 | print("\nPrint the list in its original order.")
41 |
42 | for career in careers:
43 | print(career)
44 |
45 | print("\nPrint the list in alphabetical order.")
46 |
47 | for career in sorted(careers):
48 | print(career)
49 |
50 | print("\nPrint the list in reverse alphabetical order.")
51 |
52 | for career in sorted(careers, reverse = True):
53 | print(career)
54 |
55 | print("\nPermanently sort the list in alphabetical order, and then print it out.")
56 |
57 | careers.sort()
58 |
59 | for career in careers:
60 | print(career)
61 |
62 |
63 | print("\n")
64 | """
65 | List Lengths
66 | """
67 |
68 | print("Copy two or three of the lists you made from the previous exercises, or make up two or three new lists.")
69 |
70 | languages = ['python', 'c', 'java']
71 |
72 | print("\nPrint out a series of statements that tell us how long each list is.")
73 |
74 | print("the new_careers list is {} items long.".format(len(careers)))
75 | print("the languages list is {} items long.".format(len(languages)))
--------------------------------------------------------------------------------
/eKOMEX/day 1_ Thursday/notebooks/12_lists_tuples-2_ex1_2.py:
--------------------------------------------------------------------------------
1 | print("Gymnast Scores")
2 |
3 | print("Store the possible scores a gymnast can earn from one judge in a list.")
4 |
5 | scores = []
6 | for score in range(1,11):
7 | scores.append(score)
8 |
9 | print("\nPrint out the sentence, \"The lowest possible score is ___, and the highest possible score is ___.\" Use the values from your list.")
10 |
11 | print("The lowest possible score is {0}, and the highest possible score is {1}.".format(scores[0], scores[-1]))
12 |
13 |
14 | print("\nPrint out a series of sentences, \"A judge can give a gymnast ___ points.\"")
15 | print("\nDon't worry if your first sentence reads \"A judge can give a gymnast 1 points.")
16 |
17 | for score in scores:
18 | print("A judge can give a gymnast {} points.".format(score))
19 |
20 |
21 | print("\nHowever, you get 1000 bonus internet points if you can use a for loop, and have correct grammar.")
22 |
23 | print("A judge can give a gymnast {} point.".format(scores[0]))
24 | for score in scores[1:]:
25 | print("A judge can give a gymnast {} points.".format(score))
26 |
27 | print("\nPop the first five elements (by position) and remove the last(by value).")
28 | for score in range(1,5):
29 | scores.pop(0)
30 |
31 | print(scores)
32 |
33 | scores.remove(10)
34 |
35 | print(scores)
--------------------------------------------------------------------------------
/eKOMEX/day 1_ Thursday/notebooks/12_lists_tuples-2_ex1_3.py:
--------------------------------------------------------------------------------
1 | print("First Twenty")
2 |
3 | print("Use the range() function to store the first twenty numbers (1-20) in a list, and print them out.")
4 |
5 | first_twenty = range(1,21)
6 |
7 | for number in first_twenty:
8 | print(number)
9 |
10 | print("\nFive Wallets")
11 |
12 | print("Imagine five wallets with different amounts of cash in them. Store these five values in a list")
13 |
14 | wallets = [2000, 12, 456, 9, 10000]
15 |
16 | print("The fattest wallet has {} in it.".format(sorted(wallets, reverse = True)[0]))
17 | print("The skinniest wallet has {} in it.".format(sorted(wallets)[0]))
18 | print("All together, these wallets have $ {} in them.".format(sum(wallets)))
--------------------------------------------------------------------------------
/eKOMEX/day 1_ Thursday/notebooks/13_if_statements_ex1_1.py:
--------------------------------------------------------------------------------
1 | print("####### Gymnast Scores - 2")
2 | scores = range(1, 11)
3 |
4 | for score in scores:
5 | # if score != 1:
6 | # if score >= 2:
7 | if score > 1:
8 | print("A judge can give a gymnast {} points.".format(score))
9 | else:
10 | print("A judge can give a gymnast {} point.".format(score))
11 |
12 | print("\n####### Numbers")
13 | saved_numbers = [2, 1, 5, 12, 42, 34, 52]
14 | new_numbers = [3, 1, 33, 52, 4]
15 |
16 | for new_number in new_numbers:
17 | if new_number not in saved_numbers:
18 | saved_numbers.append(new_number)
19 | print("{} is now saved".format(new_number))
20 | else:
21 | print("{} is already saved".format(new_number))
--------------------------------------------------------------------------------
/eKOMEX/day 1_ Thursday/notebooks/13_if_statements_ex1_2.py:
--------------------------------------------------------------------------------
1 | # Make a list of ten aliens, each of which is one color: 'red', 'green', or 'blue'.
2 | aliens = ["red", "green", "pink", "blue", "red", "blue", "green", "red", "red", "blue"]
3 | print("number of aliens:", len(aliens))
4 |
5 | # Use a for loop to determine the number of points a player would earn for destroying all of the aliens in your list
6 | current_score = 0
7 | for alien_color in aliens:
8 | if alien_color == "red":
9 | current_score = current_score + 5
10 | elif alien_color == "green":
11 | current_score = current_score + 10
12 | elif alien_color == "blue":
13 | current_score = current_score + 20
14 | else:
15 | print("I don't know points of color '{}'".format(alien_color))
16 | print("total points: {}".format(current_score))
--------------------------------------------------------------------------------
/eKOMEX/day 2_ Friday/assignment/ex_2.1.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "SN-mb9j3Yc1X"
7 | },
8 | "source": [
9 | "# Exercise: Lists, Dictionaries, and Functions"
10 | ]
11 | },
12 | {
13 | "cell_type": "markdown",
14 | "metadata": {
15 | "id": "72ZcTAGWYc1b"
16 | },
17 | "source": [
18 | "## Exercise 1\n",
19 | "This exercise covers variables, lists, and if-statements. You will repeat the first exercise of the first assignment but this time with functions."
20 | ]
21 | },
22 | {
23 | "cell_type": "markdown",
24 | "metadata": {
25 | "id": "-7-5-5waYc1b"
26 | },
27 | "source": [
28 | "Note: Please try to utilize functions during this exercise (instead of repeating tests!).\n",
29 | "\n",
30 | "1. Make a list of names that includes at least four people.\n",
31 | "2. Write an if test that prints a message about the room being crowded, if there are more than three people in your list.\n",
32 | "3. Modify your list so that there are only two people in it. Use one of the methods for removing people from the list, don't just redefine the list.\n",
33 | "4. Run your if test again. There should be no output this time, because there are less than three people in the list.\n",
34 | "5. Add an `else` statement to your if tests. If the `else` statement is run, have it print a message that the room is not very crowded.\n",
35 | "6. Add some names to your list, so that there are at least six people in the list. Use one of the methods for appending people from the list, don't just redefine the list.\n",
36 | "7. Modify your tests so that\n",
37 | " - If there are more than 5 people, a message is printed about the room being very crowded.\n",
38 | " - If there are 3-5 people, a message is printed about the room being crowded.\n",
39 | " - If there are 1 or 2 people, a message is printed about the room not being crowded.\n",
40 | " - If there are no people in the room, a message is printed abou the room being empty."
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": null,
46 | "metadata": {},
47 | "outputs": [],
48 | "source": []
49 | },
50 | {
51 | "cell_type": "markdown",
52 | "metadata": {
53 | "id": "K8UhXKdwYc1b"
54 | },
55 | "source": [
56 | "## Exercise 2: Dictionary Exercises 1"
57 | ]
58 | },
59 | {
60 | "cell_type": "markdown",
61 | "metadata": {
62 | "id": "vCY9U6Q2Yc1b"
63 | },
64 | "source": [
65 | "\n",
66 | "#### Mountain Heights 3\n",
67 | "- This is an extension of Mountain Heights. Make sure you save this program under a different filename, such as *mountain\\_heights_3.py*, so that you can go back to your original program if you need to.\n",
68 | " - The list of [tallest mountains in the world](http://en.wikipedia.org/wiki/List_of_mountains_by_elevation) provided all elevations in meters. Convert each of these elevations to feet, given that a meter is approximately 3.28 feet. You can do these calculations by hand at this point.\n",
69 | " - Create a new dictionary, where the keys of the dictionary are still the mountains' names. This time however, the values of the dictionary should be a list of each mountain's elevation in meters, and then in feet: `{'everest': [8848, 29029]}`\n",
70 | " - Print out just the mountains' names, by looping through the keys of your dictionary.\n",
71 | " - Print out just the mountains' elevations in meters, by looping through the values of your dictionary and pulling out the first number from each list.\n",
72 | " - Print out just the mountains' elevations in feet, by looping through the values of your dictionary and pulling out the second number from each list.\n",
73 | " - Print out a series of statements telling how tall each mountain is: \"Everest is 8848 meters tall, or 29029 feet.\"\n",
74 | "- Bonus:\n",
75 | " - Start with your original program from Mountain Heights. Write a function that reads through the elevations in meters, and returns a list of elevations in feet. Use this list to create the nested dictionary described above."
76 | ]
77 | },
78 | {
79 | "cell_type": "code",
80 | "execution_count": null,
81 | "metadata": {},
82 | "outputs": [],
83 | "source": []
84 | }
85 | ],
86 | "metadata": {
87 | "colab": {
88 | "provenance": []
89 | },
90 | "kernelspec": {
91 | "display_name": "Python 3 (ipykernel)",
92 | "language": "python",
93 | "name": "python3"
94 | },
95 | "language_info": {
96 | "codemirror_mode": {
97 | "name": "ipython",
98 | "version": 3
99 | },
100 | "file_extension": ".py",
101 | "mimetype": "text/x-python",
102 | "name": "python",
103 | "nbconvert_exporter": "python",
104 | "pygments_lexer": "ipython3",
105 | "version": "3.11.5"
106 | },
107 | "toc": {
108 | "base_numbering": 1,
109 | "nav_menu": {},
110 | "number_sections": false,
111 | "sideBar": false,
112 | "skip_h1_title": true,
113 | "title_cell": "Table of Contents",
114 | "title_sidebar": "Contents",
115 | "toc_cell": false,
116 | "toc_position": {},
117 | "toc_section_display": false,
118 | "toc_window_display": false
119 | }
120 | },
121 | "nbformat": 4,
122 | "nbformat_minor": 1
123 | }
124 |
--------------------------------------------------------------------------------
/eKOMEX/day 2_ Friday/assignment/ex_2.2.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "VDM62QDIgOyE"
7 | },
8 | "source": [
9 | "# Assignment 2.3: Data visualization\n",
10 | "\n",
11 | "In this assignment we will practice data vizualization techniques."
12 | ]
13 | },
14 | {
15 | "cell_type": "code",
16 | "execution_count": null,
17 | "metadata": {
18 | "id": "LT5rZK_-gOyM"
19 | },
20 | "outputs": [],
21 | "source": [
22 | "import numpy as np\n",
23 | "import matplotlib.pyplot as plt\n",
24 | "%matplotlib inline"
25 | ]
26 | },
27 | {
28 | "cell_type": "markdown",
29 | "metadata": {
30 | "id": "f0U5WmpYgOyO"
31 | },
32 | "source": [
33 | "# Toy data"
34 | ]
35 | },
36 | {
37 | "cell_type": "markdown",
38 | "metadata": {
39 | "id": "Wu2xvrbngOyO"
40 | },
41 | "source": [
42 | "## 1. Create a scatter plot for the following data"
43 | ]
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": null,
48 | "metadata": {
49 | "id": "WiynGMw3gOyP"
50 | },
51 | "outputs": [],
52 | "source": [
53 | "age = [32,34,19,33,57,15,62,65,32,17]\n",
54 | "income = [52000,27000,7000,23000,18500,50000,72000,22000,42000,0]"
55 | ]
56 | },
57 | {
58 | "cell_type": "markdown",
59 | "metadata": {
60 | "id": "O69eSsV4gOyQ"
61 | },
62 | "source": [
63 | "## 2. Create a simple line plot with two lines comparing the following measurements"
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": null,
69 | "metadata": {
70 | "id": "HAgZc8osgOyR"
71 | },
72 | "outputs": [],
73 | "source": [
74 | "weather_station_1 = [22,17,18,19,25,26,28,17,15,12]\n",
75 | "weather_station_2 = [24,19,17,18,24,27,29,15,14,10]"
76 | ]
77 | },
78 | {
79 | "cell_type": "markdown",
80 | "metadata": {
81 | "id": "Mnyk81qtgOyR"
82 | },
83 | "source": [
84 | "## 3. Style this plot\n",
85 | "The line colors should be red and blue; Add a legend; set the visible area for the y-axis from -5 to 35"
86 | ]
87 | },
88 | {
89 | "cell_type": "code",
90 | "execution_count": null,
91 | "metadata": {
92 | "id": "vmk570wZgOyS"
93 | },
94 | "outputs": [],
95 | "source": []
96 | },
97 | {
98 | "cell_type": "markdown",
99 | "metadata": {
100 | "id": "yL6WShOkgOyT"
101 | },
102 | "source": [
103 | "## 4. Visualize the following election data with a paired bar chart"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": null,
109 | "metadata": {},
110 | "outputs": [],
111 | "source": [
112 | "parties = [\"CDU\",\"SPD\",\"AfD\", \"FDP\", \"DIE LINKE\", \"GRÜNE\", \"CSU\", \"Sonstige\"]\n",
113 | "result_2017 = [26.8,20.5,12.6,10.7,9.2,8.9,6.2,5.0]\n",
114 | "result_2013 = [34.1,25.7,4.7,4.8,8.6,8.4,7.4,6.2]"
115 | ]
116 | },
117 | {
118 | "cell_type": "code",
119 | "execution_count": null,
120 | "metadata": {
121 | "id": "uCAM-7hygOyU"
122 | },
123 | "outputs": [],
124 | "source": []
125 | },
126 | {
127 | "cell_type": "markdown",
128 | "metadata": {
129 | "id": "gAt1VfCtgOyU"
130 | },
131 | "source": [
132 | "## 5.Create two pie charts for the following election data"
133 | ]
134 | },
135 | {
136 | "cell_type": "code",
137 | "execution_count": null,
138 | "metadata": {
139 | "id": "SIT_-LDKgOyV"
140 | },
141 | "outputs": [],
142 | "source": []
143 | }
144 | ],
145 | "metadata": {
146 | "colab": {
147 | "provenance": []
148 | },
149 | "kernelspec": {
150 | "display_name": "Python 3 (ipykernel)",
151 | "language": "python",
152 | "name": "python3"
153 | },
154 | "language_info": {
155 | "codemirror_mode": {
156 | "name": "ipython",
157 | "version": 3
158 | },
159 | "file_extension": ".py",
160 | "mimetype": "text/x-python",
161 | "name": "python",
162 | "nbconvert_exporter": "python",
163 | "pygments_lexer": "ipython3",
164 | "version": "3.11.5"
165 | },
166 | "nav_menu": {},
167 | "toc": {
168 | "base_numbering": 1,
169 | "nav_menu": {},
170 | "number_sections": true,
171 | "sideBar": true,
172 | "skip_h1_title": false,
173 | "title_cell": "Table of Contents",
174 | "title_sidebar": "Contents",
175 | "toc_cell": false,
176 | "toc_position": {},
177 | "toc_section_display": "block",
178 | "toc_window_display": false
179 | },
180 | "varInspector": {
181 | "cols": {
182 | "lenName": 16,
183 | "lenType": 16,
184 | "lenVar": 40
185 | },
186 | "kernels_config": {
187 | "python": {
188 | "delete_cmd_postfix": "",
189 | "delete_cmd_prefix": "del ",
190 | "library": "var_list.py",
191 | "varRefreshCmd": "print(var_dic_list())"
192 | },
193 | "r": {
194 | "delete_cmd_postfix": ") ",
195 | "delete_cmd_prefix": "rm(",
196 | "library": "var_list.r",
197 | "varRefreshCmd": "cat(var_dic_list()) "
198 | }
199 | },
200 | "types_to_exclude": [
201 | "module",
202 | "function",
203 | "builtin_function_or_method",
204 | "instance",
205 | "_Feature"
206 | ],
207 | "window_display": false
208 | }
209 | },
210 | "nbformat": 4,
211 | "nbformat_minor": 1
212 | }
213 |
--------------------------------------------------------------------------------
/eKOMEX/day 2_ Friday/assignment/ex_2_1_answers.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "SN-mb9j3Yc1X"
7 | },
8 | "source": [
9 | "# Exercise: Introduction to Python & Basic Concepts"
10 | ]
11 | },
12 | {
13 | "cell_type": "markdown",
14 | "metadata": {
15 | "id": "72ZcTAGWYc1b"
16 | },
17 | "source": [
18 | "## Exercise 1\n",
19 | "This exercise covers variables, lists, and if-statements. You will repeat the first exercise of the first assignment but this time with functions."
20 | ]
21 | },
22 | {
23 | "cell_type": "markdown",
24 | "metadata": {
25 | "id": "-7-5-5waYc1b"
26 | },
27 | "source": [
28 | "Note: Please try to utilize functions during this exercise (instead of repeating tests!).\n",
29 | "\n",
30 | "1. Make a list of names that includes at least four people.\n",
31 | "2. Write an if test that prints a message about the room being crowded, if there are more than three people in your list.\n",
32 | "3. Modify your list so that there are only two people in it. Use one of the methods for removing people from the list, don't just redefine the list.\n",
33 | "4. Run your if test again. There should be no output this time, because there are less than three people in the list.\n",
34 | "5. Add an `else` statement to your if tests. If the `else` statement is run, have it print a message that the room is not very crowded.\n",
35 | "6. Add some names to your list, so that there are at least six people in the list. Use one of the methods for appending people from the list, don't just redefine the list.\n",
36 | "7. Modify your tests so that\n",
37 | " - If there are more than 5 people, a message is printed about the room being very crowded.\n",
38 | " - If there are 3-5 people, a message is printed about the room being crowded.\n",
39 | " - If there are 1 or 2 people, a message is printed about the room not being crowded.\n",
40 | " - If there are no people in the room, a message is printed abou the room being empty."
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": null,
46 | "metadata": {
47 | "id": "BRivZfxYYc1b"
48 | },
49 | "outputs": [],
50 | "source": [
51 | "print(\"####### step 1\")\n",
52 | "# Make a list of names that includes at least four people.\n",
53 | "people = [\"adele\", \"ken\", \"cody\", \"caroline\"]\n",
54 | "print(people)\n",
55 | "\n",
56 | "print(\"####### step 2\")\n",
57 | "# Write an if test that prints a message about the room being crowded, if there are more than three people in your list.\n",
58 | "def check_room(people):\n",
59 | " if len(people) >= 3:\n",
60 | " print(\"The room is crowded, there are {} people.\".format(len(people)))\n",
61 | "\n",
62 | "check_room(people)\n",
63 | "\n",
64 | "print(\"####### step 3\")\n",
65 | "# Modify your list so that there are only two people in it.\n",
66 | "people.remove(\"cody\")\n",
67 | "people.remove(\"caroline\")\n",
68 | "print(people)\n",
69 | "\n",
70 | "print(\"####### step 4\")\n",
71 | "# Run your if test again.\n",
72 | "check_room(people)\n",
73 | "\n",
74 | "print(\"####### step 5\")\n",
75 | "# Add an else statement to your if tests.\n",
76 | "# If the else statement is run, have it print a message that the room is not very crowded.\n",
77 | "def check_room(people):\n",
78 | " if len(people) >= 3:\n",
79 | " print(\"The room is crowded, there are {} people.\".format(len(people)))\n",
80 | " else:\n",
81 | " print(\"The room is not crowded, there are {} people.\".format(len(people)))\n",
82 | "\n",
83 | "check_room(people)\n",
84 | "\n",
85 | "print(\"####### step 6\")\n",
86 | "# Add some names to your list, so that there are at least six people in the list.\n",
87 | "people.append(\"cody\")\n",
88 | "people.append(\"caroline\")\n",
89 | "people.append(\"adriana\")\n",
90 | "people.append(\"billy\")\n",
91 | "check_room(people)\n",
92 | "\n",
93 | "print(\"####### step 7\")\n",
94 | "# Modify your tests so that\n",
95 | "def check_room(people):\n",
96 | " # If there are more than 5 people, a message is printed about the room being very crowded.\n",
97 | " if len(people) >= 5:\n",
98 | " print(\"The room is very crowded, there are {} people.\".format(len(people)))\n",
99 | " # If there are 3-5 people, a message is printed about the room being crowded.\n",
100 | " elif len(people) >= 3:\n",
101 | " print(\"The room is crowded, there are {} people.\".format(len(people)))\n",
102 | " # If there are 1 or 2 people, a message is printed about the room not being crowded.\n",
103 | " elif len(people) >= 1:\n",
104 | " print(\"The room is not crowded, there are {} people.\".format(len(people)))\n",
105 | " # If there are no people in the room, a message is printed abou the room being empty.\n",
106 | " else:\n",
107 | " print(\"The room is empty.\")\n",
108 | "\n",
109 | "check_room(people)\n",
110 | "check_room(people[:4])\n",
111 | "check_room(people[:2])\n",
112 | "check_room([])"
113 | ]
114 | },
115 | {
116 | "cell_type": "markdown",
117 | "metadata": {
118 | "id": "K8UhXKdwYc1b"
119 | },
120 | "source": [
121 | "## Dictionary Exercises 1"
122 | ]
123 | },
124 | {
125 | "cell_type": "markdown",
126 | "metadata": {
127 | "id": "vCY9U6Q2Yc1b"
128 | },
129 | "source": [
130 | "\n",
131 | "#### Mountain Heights 3\n",
132 | "- This is an extension of [Mountain Heights](#exercise_mountain_heights). Make sure you save this program under a different filename, such as *mountain\\_heights_3.py*, so that you can go back to your original program if you need to.\n",
133 | " - The list of [tallest mountains in the world](http://en.wikipedia.org/wiki/List_of_mountains_by_elevation) provided all elevations in meters. Convert each of these elevations to feet, given that a meter is approximately 3.28 feet. You can do these calculations by hand at this point.\n",
134 | " - Create a new dictionary, where the keys of the dictionary are still the mountains' names. This time however, the values of the dictionary should be a list of each mountain's elevation in meters, and then in feet: {'everest': [8848, 29029]}\n",
135 | " - Print out just the mountains' names, by looping through the keys of your dictionary.\n",
136 | " - Print out just the mountains' elevations in meters, by looping through the values of your dictionary and pulling out the first number from each list.\n",
137 | " - Print out just the mountains' elevations in feet, by looping through the values of your dictionary and pulling out the second number from each list.\n",
138 | " - Print out a series of statements telling how tall each mountain is: \"Everest is 8848 meters tall, or 29029 feet.\"\n",
139 | "- Bonus:\n",
140 | " - Start with your original program from [Mountain Heights](#exercise_mountain_heights). Write a function that reads through the elevations in meters, and returns a list of elevations in feet. Use this list to create the nested dictionary described above."
141 | ]
142 | },
143 | {
144 | "cell_type": "code",
145 | "source": [
146 | "mountain_dict = {\"Mount Everest\": 8448, \"K2\": 8611, \"Kanchenjunga\":8586, \"Lhotse\" : 8516, \"Cho Oyu\" : 8201}\n",
147 | "\n",
148 | "mountain_dict_2 = {}\n",
149 | "\n",
150 | "for mountain_name in mountain_dict:\n",
151 | "\tmountain_dict_2[mountain_name] = [mountain_dict[mountain_name], mountain_dict[mountain_name] * 3.82 ]\n",
152 | "\n",
153 | "# Print out just the mountains' names, by looping through the keys of your dictionary.\n",
154 | "\n",
155 | "for mountain_name in mountain_dict_2:\n",
156 | "\tprint(\"{} is a mountain.\".format(mountain_name))\n",
157 | "\n",
158 | "# Print out just the mountains' elevations in meters, by looping through the values of your dictionary and\n",
159 | "# pulling out the first number from each list.\n",
160 | "print()\n",
161 | "for mountain_height in mountain_dict_2.values():\n",
162 | "\tprint(\"{} is a mountain's height in meters.\".format(mountain_height[0]))\n",
163 | "\n",
164 | "# Print out just the mountains' elevations in feet, by looping through the values of your dictionary and\n",
165 | "# pulling out the second number from each list.\n",
166 | "print()\n",
167 | "for mountain_height in mountain_dict_2.values():\n",
168 | "\tprint(\"{} is a mountain's height in feet.\".format(mountain_height[1]))\n",
169 | "\n",
170 | "# Print out a series of statements telling how tall each mountain is: \"Everest is 8848 meters tall, or 29029 feet.\"\n",
171 | "print()\n",
172 | "for mountain_name in mountain_dict_2:\n",
173 | "\tprint(\"{} is {} meters tall, or {} feet tall.\".format(mountain_name, mountain_dict_2[mountain_name][0], mountain_dict_2[mountain_name][1]))"
174 | ],
175 | "metadata": {
176 | "id": "ubkwD2i09qKN"
177 | },
178 | "execution_count": null,
179 | "outputs": []
180 | }
181 | ],
182 | "metadata": {
183 | "kernelspec": {
184 | "display_name": "Python 2",
185 | "language": "python",
186 | "name": "python2"
187 | },
188 | "language_info": {
189 | "codemirror_mode": {
190 | "name": "ipython",
191 | "version": 2
192 | },
193 | "file_extension": ".py",
194 | "mimetype": "text/x-python",
195 | "name": "python",
196 | "nbconvert_exporter": "python",
197 | "pygments_lexer": "ipython2",
198 | "version": "2.7.12"
199 | },
200 | "toc": {
201 | "base_numbering": 1,
202 | "nav_menu": {},
203 | "number_sections": false,
204 | "sideBar": false,
205 | "skip_h1_title": true,
206 | "title_cell": "Table of Contents",
207 | "title_sidebar": "Contents",
208 | "toc_cell": false,
209 | "toc_position": {},
210 | "toc_section_display": false,
211 | "toc_window_display": false
212 | },
213 | "colab": {
214 | "provenance": []
215 | }
216 | },
217 | "nbformat": 4,
218 | "nbformat_minor": 0
219 | }
--------------------------------------------------------------------------------
/eKOMEX/day 2_ Friday/notebooks/figure_1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Indiiigo/Intro_to_python/3035764946d2c52d3d86d9e1db7ece284b0f59ee/eKOMEX/day 2_ Friday/notebooks/figure_1.pdf
--------------------------------------------------------------------------------
/eKOMEX/day 2_ Friday/notebooks/figure_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Indiiigo/Intro_to_python/3035764946d2c52d3d86d9e1db7ece284b0f59ee/eKOMEX/day 2_ Friday/notebooks/figure_1.png
--------------------------------------------------------------------------------