Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
249 changes: 213 additions & 36 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -25,11 +25,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"PLAY\n",
"FILLING\n",
"BAR\n",
"THEATRE\n",
"EASYGOING\n",
"DATE\n",
"LEAD\n",
"THAT\n",
"STORY\n",
"ISLAND\n"
]
}
],
"source": [
"# your code here"
"for word in words: \n",
" print(word.upper())"
]
},
{
Expand All @@ -41,11 +59,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['filling', 'theatre', 'easygoing', 'story', 'island']"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here"
"# Create an empty list to store words with 5 or more letters\n",
"new_list = []\n",
"\n",
"# Loop through each word in the words\n",
"for word in words:\n",
" # Check if the length of the word is 5 or more letters\n",
" if len(word) >= 5:\n",
" # If the condition is met, append the word to the new_list\n",
" new_list.append(word)\n",
"\n",
"# Display the new_list containing words longer or equal than 5 characters\n",
"new_list"
]
},
{
Expand All @@ -57,11 +97,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"theatre\n",
"that\n"
]
}
],
"source": [
"# your code here"
"for word in words:\n",
" if word.startswith(\"t\"):\n",
" print(word)\n",
" \n",
" else:\n",
" pass"
]
},
{
Expand All @@ -80,11 +134,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 50,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n"
]
}
],
"source": [
"# your code here"
"#create an empty list\n",
"square_list = []\n",
"#loop through each number from 1 to 10\n",
"for number in range (1,11):\n",
" #calculate the square of each number and add it to the square list.\n",
" square_list.append(number**2)\n",
"#print the list\n",
"print(square_list)"
]
},
{
Expand All @@ -96,11 +165,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 49,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 9, 25, 49, 81]\n"
]
}
],
"source": [
"# your code here"
"#create an empty list\n",
"odd_square_list = []\n",
"#loop through each number from 1 to 10\n",
"for number in range (1,11):\n",
" # check if the number is odd\n",
" if number % 2 == 1:\n",
" #calculate the square of each number and add it to the square list.\n",
" odd_square_list.append(number**2)\n",
"#print the list\n",
"print(odd_square_list)"
]
},
{
Expand All @@ -114,9 +200,28 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[64, 256, 576, 1024, 1600, 2304, 3136, 4096, 5184, 6400, 7744, 9216, 10816, 12544, 14400, 16384, 18496, 20736, 23104, 25600, 28224, 30976, 33856, 36864, 40000, 43264, 46656, 50176, 53824, 57600, 61504, 65536, 69696, 73984, 78400, 82944, 87616, 92416, 97344, 102400, 107584, 112896, 118336, 123904, 129600, 135424, 141376, 147456, 153664, 160000, 166464, 173056, 179776, 186624, 193600, 200704, 207936, 215296, 222784, 230400, 238144, 246016, 254016, 262144, 270400, 278784, 287296, 295936, 304704, 313600, 322624, 331776, 341056, 350464, 360000, 369664, 379456, 389376, 399424, 409600, 419904, 430336, 440896, 451584, 462400, 473344, 484416, 495616, 506944, 518400, 529984, 541696, 553536, 565504, 577600, 589824, 602176, 614656, 627264, 640000, 652864, 665856, 678976, 692224, 705600, 719104, 732736, 746496, 760384, 774400, 788544, 802816, 817216, 831744, 846400, 861184, 876096, 891136, 906304, 921600, 937024, 952576, 968256, 984064]\n"
]
}
],
"source": [
"# your code here"
"#create an empty list\n",
"new_square_list = []\n",
"\n",
"#loop through each number from 1 to 1000\n",
"for number in range(1, 1000):\n",
" # check if the number is a multiple of 8\n",
" if number % 8 == 0:\n",
" #calculate the square of each number and add it to the square list.\n",
" new_square_list.append(number**2)\n",
"\n",
"#print the list\n",
"print(new_square_list)"
]
},
{
Expand All @@ -128,7 +233,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 56,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -170,11 +275,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 57,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5\n"
]
}
],
"source": [
"# your code here"
"#Calculated the length of the dictionary\n",
"number_of_people = len(people)\n",
"#Print\n",
"print(number_of_people)"
]
},
{
Expand All @@ -186,11 +302,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 71,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n"
]
}
],
"source": [
"# your code here"
"#Start counter of people with kids by 0\n",
"people_with_kids = 0\n",
"#Loop through each persin in the list\n",
"for person in people:\n",
" #Check if the person has one or more kids\n",
" if person[\"n_kids\"] > 0:\n",
" #Add 1 to it\n",
" people_with_kids +=1\n",
"#Print the results\n",
"print(people_with_kids)"
]
},
{
Expand All @@ -204,9 +337,24 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10\n"
]
}
],
"source": [
"# your code here"
"#Start counter of total kids by 0\n",
"total_kids = 0\n",
"#Loop through each persin in the list\n",
"for person in people:\n",
" #Add number of kids for each person to the total\n",
" total_kids += person[\"n_kids\"]\n",
"#Print the results\n",
"print(total_kids)"
]
},
{
Expand All @@ -220,15 +368,49 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[{'name': 'Juan', 'age': 34, 'n_kids': 2},\n",
" {'name': 'Pepe', 'age': 27, 'n_kids': 0},\n",
" {'name': 'Sonia', 'age': 41, 'n_kids': 2},\n",
" {'name': 'Lucía', 'age': 22, 'n_kids': 3},\n",
" {'name': 'Leo', 'age': 55, 'n_kids': 5}]"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here"
"#Only Sonia and Lucia are having an extra kid next year.\n",
"\n",
"# Create a new list to store the updated people's info\n",
"people_in_a_year = []\n",
"\n",
"# Loop through each person in the original list\n",
"for person in people:\n",
" # Copy the person's information to a new dictionary\n",
" updated_person = person.copy()\n",
" \n",
" # Check if the person's name ends with \"a\"\n",
" if updated_person[\"name\"].endswith(\"a\"):\n",
" # Add an extra kid\n",
" updated_person[\"n_kids\"] += 1\n",
" \n",
" # Add the updated person's dictionary to the new list\n",
" people_in_a_year.append(updated_person)\n",
"\n",
"# Display the updated list\n",
"people_in_a_year"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -242,7 +424,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
},
"toc": {
"base_numbering": 1,
Expand Down Expand Up @@ -285,11 +467,6 @@
"_Feature"
],
"window_display": false
},
"vscode": {
"interpreter": {
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
}
}
},
"nbformat": 4,
Expand Down