Skip to content

Commit 0bbdcf0

Browse files
committed
exercises + notes
1 parent 9864aa5 commit 0bbdcf0

File tree

3 files changed

+7352
-50
lines changed

3 files changed

+7352
-50
lines changed

Exercises/EN/Basic/04_Conditional_Statements.ipynb

+139-34
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
{
4848
"cell_type": "code",
49-
"execution_count": 2,
49+
"execution_count": 1,
5050
"metadata": {},
5151
"outputs": [
5252
{
@@ -63,6 +63,7 @@
6363
"read_file = reader(opened_file)\n",
6464
"apps_data = list(read_file)\n",
6565
"\n",
66+
"\n",
6667
"ratings = []\n",
6768
"for row in apps_data[1:]:\n",
6869
" rating = float(row[7])\n",
@@ -123,11 +124,42 @@
123124
},
124125
{
125126
"cell_type": "code",
126-
"execution_count": 43,
127+
"execution_count": null,
127128
"metadata": {},
128129
"outputs": [],
130+
"source": []
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": 6,
135+
"metadata": {},
136+
"outputs": [
137+
{
138+
"name": "stdout",
139+
"output_type": "stream",
140+
"text": [
141+
"3.3767258382642997\n"
142+
]
143+
}
144+
],
129145
"source": [
130146
"## Start your code below:\n",
147+
"opened_file = open('AppleStore.csv', encoding='utf8')\n",
148+
"from csv import reader\n",
149+
"read_file = reader(opened_file)\n",
150+
"apps_data = list(read_file)\n",
151+
"\n",
152+
"free_apps_ratings = []\n",
153+
"\n",
154+
"\n",
155+
"for row in apps_data[1:]: ##for each row in the dataset\n",
156+
" rating = float(row[7]) ##the variable rating is a float of the 7th column in each row\n",
157+
" price=float(row[4]) ##the variable price is a float of the 4th column in each row\n",
158+
" if price==0.0: ##if the price is 0.0\n",
159+
" free_apps_ratings.append(rating) #then the rating is added to the free_apps_rating\n",
160+
"\n",
161+
"avg_rating_free = sum(free_apps_ratings) / len(free_apps_ratings) ##computing the average\n",
162+
"print(avg_rating_free)\n",
131163
"\n",
132164
"\n"
133165
]
@@ -224,17 +256,9 @@
224256
},
225257
{
226258
"cell_type": "code",
227-
"execution_count": 47,
259+
"execution_count": 7,
228260
"metadata": {},
229-
"outputs": [
230-
{
231-
"name": "stdout",
232-
"output_type": "stream",
233-
"text": [
234-
"10\n"
235-
]
236-
}
237-
],
261+
"outputs": [],
238262
"source": [
239263
"#1. A Boolean value.\n",
240264
"\n",
@@ -363,13 +387,26 @@
363387
},
364388
{
365389
"cell_type": "code",
366-
"execution_count": 52,
390+
"execution_count": 9,
367391
"metadata": {},
368-
"outputs": [],
392+
"outputs": [
393+
{
394+
"name": "stdout",
395+
"output_type": "stream",
396+
"text": [
397+
"this is not free\n"
398+
]
399+
}
400+
],
369401
"source": [
370-
"price = 0\n",
402+
"price = 4\n",
371403
"\n",
372-
"#start your code here:\n"
404+
"#start your code here:\n",
405+
"if price ==0:\n",
406+
" print(\"this is free\")\n",
407+
"else: \n",
408+
" if price>0:\n",
409+
" print(\"this is not free\")\n"
373410
]
374411
},
375412
{
@@ -454,7 +491,7 @@
454491
},
455492
{
456493
"cell_type": "code",
457-
"execution_count": 55,
494+
"execution_count": 10,
458495
"metadata": {},
459496
"outputs": [
460497
{
@@ -522,24 +559,33 @@
522559
},
523560
{
524561
"cell_type": "code",
525-
"execution_count": 58,
562+
"execution_count": 13,
526563
"metadata": {},
527-
"outputs": [],
564+
"outputs": [
565+
{
566+
"name": "stdout",
567+
"output_type": "stream",
568+
"text": [
569+
"3.720948742438714\n"
570+
]
571+
}
572+
],
528573
"source": [
529574
"# INITIAL CODE\n",
530575
"opened_file = open('AppleStore.csv', encoding='utf8')\n",
531576
"from csv import reader\n",
532577
"read_file = reader(opened_file)\n",
533578
"apps_data = list(read_file)\n",
534579
"\n",
535-
"free_apps_ratings = []\n",
580+
"non_free_apps_ratings = []\n",
536581
"for row in apps_data[1:]:\n",
537582
" rating = float(row[7])\n",
538583
" price = float(row[4]) \n",
539-
" if price == 0.0:\n",
540-
" free_apps_ratings.append(rating)\n",
584+
" if price != 0.0:\n",
585+
" non_free_apps_ratings.append(rating)\n",
541586
" \n",
542-
"avg_rating_free = sum(free_apps_ratings) / len(free_apps_ratings)"
587+
"avg_rating_non_free = sum(non_free_apps_ratings) / len(non_free_apps_ratings)\n",
588+
"print(avg_rating_non_free)"
543589
]
544590
},
545591
{
@@ -638,9 +684,17 @@
638684
},
639685
{
640686
"cell_type": "code",
641-
"execution_count": 63,
687+
"execution_count": 16,
642688
"metadata": {},
643-
"outputs": [],
689+
"outputs": [
690+
{
691+
"name": "stdout",
692+
"output_type": "stream",
693+
"text": [
694+
"3.343928035982009\n"
695+
]
696+
}
697+
],
644698
"source": [
645699
"#reading the dataset\n",
646700
"opened_file = open('AppleStore.csv', encoding='utf8')\n",
@@ -650,6 +704,15 @@
650704
"\n",
651705
"#start your code here:\n",
652706
"#Initialize an empty list named non_games_ratings.\n",
707+
"non_games_ratings=[]\n",
708+
"for row in apps_data[1:]:\n",
709+
" rating=float(row[7])\n",
710+
" genre=row[11]\n",
711+
"\n",
712+
" if genre !='Games':\n",
713+
" non_games_ratings.append(rating)\n",
714+
"avg_ratings_non_games=sum(non_games_ratings)/len(non_games_ratings)\n",
715+
"print(avg_ratings_non_games)\n",
653716
"\n",
654717
"#Loop through the apps_data\n",
655718
"\n",
@@ -1054,25 +1117,34 @@
10541117
},
10551118
{
10561119
"cell_type": "code",
1057-
"execution_count": 79,
1120+
"execution_count": 18,
10581121
"metadata": {},
1059-
"outputs": [],
1122+
"outputs": [
1123+
{
1124+
"name": "stdout",
1125+
"output_type": "stream",
1126+
"text": [
1127+
"3.8904235727440146\n"
1128+
]
1129+
}
1130+
],
10601131
"source": [
10611132
"opened_file = open('AppleStore.csv', encoding='utf8')\n",
10621133
"from csv import reader\n",
10631134
"read_file = reader(opened_file)\n",
10641135
"apps_data = list(read_file)\n",
10651136
"\n",
1066-
"free_games_social_ratings = []\n",
1137+
"non_free_games_social_ratings = []\n",
10671138
"for row in apps_data[1:]:\n",
10681139
" rating = float(row[7])\n",
10691140
" genre = row[11]\n",
10701141
" price = float(row[4])\n",
10711142
" \n",
1072-
" if (genre == 'Social Networking' or genre == 'Games') and price == 0:\n",
1073-
" free_games_social_ratings.append(rating)\n",
1143+
" if (genre == 'Social Networking' or genre == 'Games') and price != 0:\n",
1144+
" non_free_games_social_ratings.append(rating)\n",
10741145
" \n",
1075-
"avg_free = sum(free_games_social_ratings) / len(free_games_social_ratings)\n",
1146+
"avg_non_free = sum(non_free_games_social_ratings) / len(non_free_games_social_ratings)\n",
1147+
"print(avg_non_free)\n",
10761148
"\n",
10771149
"# Non-free apps (average)"
10781150
]
@@ -1555,7 +1627,7 @@
15551627
},
15561628
{
15571629
"cell_type": "code",
1558-
"execution_count": 94,
1630+
"execution_count": 20,
15591631
"metadata": {},
15601632
"outputs": [],
15611633
"source": [
@@ -1567,8 +1639,41 @@
15671639
"\n",
15681640
"for app in apps_data[1:]:\n",
15691641
" price = float(app[4])\n",
1570-
" # Complete code from here"
1642+
" # Complete code from here\n",
1643+
" if price==0.0:\n",
1644+
" app.append(\"free)\")\n",
1645+
" elif price >0 and price< 20:\n",
1646+
" app.append(\"affordable\")\n",
1647+
" elif price >=20 and price <50:\n",
1648+
" app.append(\"expensive\")\n",
1649+
" elif price >= 50: \n",
1650+
" app.append(\"very expensive\")\n",
1651+
"apps_data[0].append(\"price_label\")"
15711652
]
1653+
},
1654+
{
1655+
"cell_type": "code",
1656+
"execution_count": 22,
1657+
"metadata": {},
1658+
"outputs": [
1659+
{
1660+
"name": "stdout",
1661+
"output_type": "stream",
1662+
"text": [
1663+
"['id', 'track_name', 'size_bytes', 'currency', 'price', 'rating_count_tot', 'rating_count_ver', 'user_rating', 'user_rating_ver', 'ver', 'cont_rating', 'prime_genre', 'sup_devices.num', 'ipadSc_urls.num', 'lang.num', 'vpp_lic', 'price_label']\n"
1664+
]
1665+
}
1666+
],
1667+
"source": [
1668+
"print(apps_data[0])"
1669+
]
1670+
},
1671+
{
1672+
"cell_type": "code",
1673+
"execution_count": null,
1674+
"metadata": {},
1675+
"outputs": [],
1676+
"source": []
15721677
}
15731678
],
15741679
"metadata": {
@@ -1587,7 +1692,7 @@
15871692
"name": "python",
15881693
"nbconvert_exporter": "python",
15891694
"pygments_lexer": "ipython3",
1590-
"version": "3.7.1"
1695+
"version": "3.11.5"
15911696
}
15921697
},
15931698
"nbformat": 4,

0 commit comments

Comments
 (0)