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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "PythonForDataScience_intro.ipynb",
      "provenance": [],
      "collapsed_sections": [
        "Zfms3DPGJbL-",
        "rhZuvfjORCEh",
        "rlcQJDLlFUuz",
        "kRjiRzYl9Xuy",
        "I3qwY_iVxkuX",
        "crVFfqHF_7Qj",
        "fRrO-BOOeUCE",
        "xEPReYdxm-E5"
      ]
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "These are called cells.  There are 2 types of cells: code and text. We can add more cells by clicking the + buttons above!\n",
        "\n",
        "In a code cell you can type some code and then you execute the code by pressing Shift + Enter\n",
        "\n",
        "In a text cell you can also format text!\n",
        "# Chapter 1!\n",
        "Sub text here!\n",
        "\n",
        "## Sub-Header\n",
        "\n",
        "### Sub-Sub-Header"
      ],
      "metadata": {
        "id": "SS1aONKU9FyM"
      }
    },
    {
      "cell_type": "code",
      "source": [
        ""
      ],
      "metadata": {
        "id": "zeoHP5FokIWM"
      },
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        ""
      ],
      "metadata": {
        "id": "FfYdhQ-fkI76"
      },
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        ""
      ],
      "metadata": {
        "id": "gw6grf6bkJPp"
      },
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        ""
      ],
      "metadata": {
        "id": "bmIURVp3kLfB"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "2+2"
      ],
      "metadata": {
        "id": "wiVCBtg89Dz1",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "d625d75d-51e9-471a-c4a4-3d111c1b2aa8"
      },
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "4"
            ]
          },
          "metadata": {},
          "execution_count": 2
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "2+2\n",
        "4+4"
      ],
      "metadata": {
        "id": "SBBED0rE6rxn",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "59d3f317-0a0f-4dd7-c617-52f37b52abb3"
      },
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "8"
            ]
          },
          "metadata": {},
          "execution_count": 3
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "print(2+2)\n",
        "print(4+4)"
      ],
      "metadata": {
        "id": "hSZ2aNVh6r3u",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "59e22b79-2a12-4d63-f7d4-93c3e4814c13"
      },
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "4\n",
            "8\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "print('hello world!')"
      ],
      "metadata": {
        "id": "9JkDnOvG6zsp",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "3f1a4557-3ecb-48d7-81cf-3969891917bb"
      },
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "hello world!\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        ""
      ],
      "metadata": {
        "id": "iFWtrUbJCiad"
      },
      "execution_count": 5,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "print('hello world',2+2,'this is python')"
      ],
      "metadata": {
        "id": "isR8teAB6zu_",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "70668aee-bc05-4382-baf7-1d6a646b808d"
      },
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "hello world 4 this is python\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "print('hello world',2+2,'this is python',sep='')"
      ],
      "metadata": {
        "id": "qS7VIsa37RKx",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "8c8eef92-d487-4cda-853c-8632d2e8bdb2"
      },
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "hello world4this is python\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# everything to the right of a # is not run as code, this is called a comment!\n",
        "2+2 # this is adding two plus two"
      ],
      "metadata": {
        "id": "xIoQO0ix6zxJ",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "73232415-f158-45ee-f62e-4515c3cebc7c"
      },
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "4"
            ]
          },
          "metadata": {},
          "execution_count": 8
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# we can add strings together!\n",
        "print('hello'+'world')"
      ],
      "metadata": {
        "id": "TMuz1Mlc6zzv",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "ce9aef73-2ec3-4f36-d72f-12637f59f0a6"
      },
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "helloworld\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "print('hello ' + ' world')"
      ],
      "metadata": {
        "id": "FfMWZGHRCtsz",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "49073001-1c35-4789-e280-06269cdb18c4"
      },
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "hello  world\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "print('hello'+5)"
      ],
      "metadata": {
        "id": "i2VDUtLgCxPD",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 166
        },
        "outputId": "6945f455-ed96-4381-ebf9-a9ac520b7fd6"
      },
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "error",
          "ename": "TypeError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-11-1f1168554856>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'hello'\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "A mobile store MobiWorld sells different mobile phones to customers. For each order that is placed, the store keeps a record of various attributes related to the mobile, like Price, Brand, RAM (GB), and Internal Storage (GB).\n",
        "\n",
        "Let's learn Python using the context of the store's data.\n"
      ],
      "metadata": {
        "id": "qA3wyngS6oI3"
      }
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Zfms3DPGJbL-"
      },
      "source": [
        "## 1.1 Intro to Variables"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lJcCrrGLmUQL"
      },
      "source": [
        "First, we have to store our data to a variable that can be used to extract the stored information later. Let's take an example of how we can do that in Python.\n",
        "\n",
        "Q. Suppose the store sold an Apple iPhone (4GB, 128GB) for $900. Store this information in the variables **price**, **brand**, **ram**, and **storage**.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QFfVcPv3nuNp",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "b617ebe1-f784-4546-ba07-cfbe465715ac"
      },
      "source": [
        "# store the price (in dollars) of the mobile in variable 'price'\n",
        "price = 900\n",
        "# print the value saved in the variable 'price'\n",
        "print('The price of the mobile is $',price,sep='')"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The price of the mobile is $900\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "PtM8OsxBpqjc",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "f3996ecc-9a95-42d5-e41e-e2e5dea438a7"
      },
      "source": [
        "# store the brand name of the mobile in variable 'brand'.\n",
        "brand = 'Apple'\n",
        "# print the value saved in the variable 'brand'\n",
        "print('The brand of the mobile is',brand)"
      ],
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The brand of the mobile is Apple\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YuF62kesqH4k",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "76fed9ae-2572-4eda-e084-394f2ad4ebe6"
      },
      "source": [
        "# store the RAM (in GB) of the mobile in variable 'ram'.\n",
        "ram = 4\n",
        "# print the value saved in the variable 'ram'\n",
        "print('The RAM of the mobile is', ram,'GB')"
      ],
      "execution_count": 15,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The RAM of the mobile is 4 GB\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "km7ePn3WqUVk",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "fba88284-37e7-4e3c-a7ff-ec30a9f5d05b"
      },
      "source": [
        "# store the internal storage (in GB) of the mobile in variable 'storage'.\n",
        "storage = 128\n",
        "# print the value saved in the variable 'Memory'\n",
        "print('The internal storage of the mobile is', storage, 'GB')"
      ],
      "execution_count": 16,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The internal storage of the mobile is 128 GB\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6Hl1V6TfC3PN"
      },
      "source": [
        "Q. Let's say the store wants to save the information on the billing status of the above phone in a boolean variable. Write the code in Python to implement the same."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_jZ5ynflEGlJ",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "e14ebcc0-fd09-45ad-a5d6-6c1a23eebb3a"
      },
      "source": [
        "# a special type of variable stores just True/False values.  This is called a boolean variable.\n",
        "# create a boolean variable 'is_billed' to save the billing information\n",
        "is_billed = True\n",
        "print(is_billed)"
      ],
      "execution_count": 17,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "True\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3V2CNbizt63k"
      },
      "source": [
        "The value that we store in a variable can be a number or a set of characters or a boolean variable (True/False). For example, a price is a number while the brand name is a set of characters which is also known as a string in python. Whenever we store a value in a variable, Python automatically assigns a data type to that variable based on the value. It also allows us to check the data type of the variable.\n",
        "\n",
        "Q. Check the data type of the variables **price**, **brand**, **ram**, and **storage**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "g4KOBpxyvbIR",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "97d5d8b1-dbf0-4af9-ea4d-c09bfb2591e5"
      },
      "source": [
        "# check the data-type using the type function\n",
        "type(price)"
      ],
      "execution_count": 18,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "int"
            ]
          },
          "metadata": {},
          "execution_count": 18
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "M8vCNgGavtIw",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "74b15c50-043e-4936-fbf9-a1e0023f7cae"
      },
      "source": [
        "# check the data-type using the type function\n",
        "type(brand)"
      ],
      "execution_count": 19,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "str"
            ]
          },
          "metadata": {},
          "execution_count": 19
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "4Tur0cIAwTxr",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "d9f0f2c8-f6a6-4cc3-8a19-d894c44b840a"
      },
      "source": [
        "# check the data-type using the type function\n",
        "type(ram)"
      ],
      "execution_count": 20,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "int"
            ]
          },
          "metadata": {},
          "execution_count": 20
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "r0kULhRIwVbP",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "94c9d25b-2c12-4474-949d-166692d7a6ce"
      },
      "source": [
        "# check the data-type using the type function\n",
        "type(storage)"
      ],
      "execution_count": 21,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "int"
            ]
          },
          "metadata": {},
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Q_81HC3LFF8_",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "3f65f94d-2665-48e1-9eb5-504555baa225"
      },
      "source": [
        "# check the data-type using the type function\n",
        "type(is_billed)"
      ],
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "bool"
            ]
          },
          "metadata": {},
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "MP4Csswyq1mG"
      },
      "source": [
        "Q. Let's say a customer buys two Apple iPhones (4GB, 128GB) at a price of $900 each. What will be the total bill that the customer has to pay?"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "PUv9ztT6sG3i",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "ba06c164-32df-4a91-dc00-7fd53541e9e3"
      },
      "source": [
        "# calcuate the total bill and store it in variable 'bill'\n",
        "bill = price + price\n",
        "# the same result can be achieved by multiplication.\n",
        "bill = price*2\n",
        "print('The bill amount is $',bill,sep='')"
      ],
      "execution_count": 23,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The bill amount is $1800\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "t9Xp42rvP5lJ"
      },
      "source": [
        "Q. Let's say the store provides a discount of \\$15 dollars on the Apple iPhone (4GB, 128GB) that costs $900. What will be the price of the iPhone after the discount?\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qjha3bvzQovj",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "e24b8c0c-b30e-4b16-a221-bf906075c8d1"
      },
      "source": [
        "# store the price (in dollars) of the mobile in variable 'price'\n",
        "price = 900\n",
        "# store the discount amount in variable 'discount'\n",
        "discount = 15\n",
        "# calculate the discounted price\n",
        "price_after_discount = price - discount\n",
        "print('The price of the iPhone after the discount is $',price_after_discount,sep='')"
      ],
      "execution_count": 24,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The price of the iPhone after the discount is $885\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zZvOG69cVKYA"
      },
      "source": [
        "Q. Let's say a customer buys two Apple iPhones (4GB, 128GB) and pays a total bill of \\$1800. Write the Python code to find the price of an Apple iPhone."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jd7Z5MDBWXkY",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "b19c4cbb-1ffa-4e13-bb34-d0ee08966d66"
      },
      "source": [
        "# store the bill (in dollars) of the two mobiles in variable 'bill'\n",
        "bill = 1800\n",
        "# calculate the price of one mobile\n",
        "price = bill / 2\n",
        "print('The price of an Apple iPhone is $',price,sep='')"
      ],
      "execution_count": 25,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The price of an Apple iPhone is $900.0\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "G1LuAO-rRjhK"
      },
      "source": [
        "Q. Let's say a customer buys x numbers of Apple iPhones (4GB, 128GB) for $900 each. The total bill that the customer pays is \\$3600. Write the Python code to find the value of x."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "UaiRRd3WReW6",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "dee71494-69a9-43a6-97c1-3d79efc0d1f1"
      },
      "source": [
        "# store the bill (in dollars) of the mobile in variable 'bill'\n",
        "bill = 3600\n",
        "# store the price (in dollars) of the mobile in variable 'price'\n",
        "price = 900\n",
        "# calculate the number of iPhones that the customer buys\n",
        "x = bill // price\n",
        "# double divided forces the answer to be an integer!\n",
        "print('The customer buys', x, 'Apple iPhones')"
      ],
      "execution_count": 26,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The customer buys 4 Apple iPhones\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cG-aP2YlFNzB"
      },
      "source": [
        "Q. Suppose the store plans to provide a 4.5% discount on the Apple iPhone. What will be the discounted price of the mobile?"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3fpYu_Z8Ndf0"
      },
      "source": [
        "**Type Conversion**: The process of converting one data type to another data type is called type conversion. \n",
        "\n",
        "In Python, we can perform two types of type conversion.\n",
        "\n",
        "1. Implicit Type Conversion - Here, Python automatically converts one data type to another in order to avoid data loss.\n",
        "\n",
        "2. Explicit Type Conversion - Here, the user can convert the data type of a variable to the required data type by using the in-built functions int(), float(), str(), etc.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "RmmOkRrwG6ac",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "89184212-8eb2-4a24-9f87-ac48387be698"
      },
      "source": [
        "# store the price (in dollars) of the mobile in variable 'price'\n",
        "price = 900\n",
        "# calculate the discount amount\n",
        "discount = price * 0.045\n",
        "# calculate the discounted price\n",
        "discounted_price = price - discount\n",
        "print('The discounted price of the iPhone is ' + str(discounted_price))"
      ],
      "execution_count": 27,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The discounted price of the iPhone is 859.5\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "type(discounted_price)"
      ],
      "metadata": {
        "id": "usYUYXiOCdVt",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "b999ecdf-ba6f-4fb0-dc30-3cbac0c5ac6a"
      },
      "execution_count": 28,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "float"
            ]
          },
          "metadata": {},
          "execution_count": 28
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2SrYvKgAZv2c"
      },
      "source": [
        "Now, let's check the data type of the variables 'discount' and 'price'"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "5vU-mAkiZ92S",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "90eedeaa-9184-4592-d7ec-db9fe7493a62"
      },
      "source": [
        "print('The data type of variable price is',type(price))\n",
        "print('The data type of variable discount is',type(discount))"
      ],
      "execution_count": 29,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The data type of variable price is <class 'int'>\n",
            "The data type of variable discount is <class 'float'>\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "q05dBOmTwXuE"
      },
      "source": [
        "As we can see, the data type of 'discount' is float as Python is implicitly converting the lower data type to a higher data type to avoid data loss.\n",
        "\n",
        "Suppose we want to add the variables **brand**, **ram**, and **storage**. \n",
        "\n",
        "Will the implicit conversion work?\n",
        "\n",
        "Let's try it!"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "F-JdovnFdDpu",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 166
        },
        "outputId": "856db8c1-437b-4ffd-d41a-15eaf6d255ab"
      },
      "source": [
        "print(brand + ' ' + ram + 'GB')"
      ],
      "execution_count": 30,
      "outputs": [
        {
          "output_type": "error",
          "ename": "TypeError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-30-f953f257e67c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbrand\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m' '\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mram\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m'GB'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "R6NNDgIKdR8T"
      },
      "source": [
        "As we can see from the output, the TypeError is being raised which indicates that Python is not able to use Implicit Conversion in such conditions.\n",
        "\n",
        "But, we can do an explicit conversion for such cases."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "sSG3cdv0w630",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "4df36bfa-6f4c-4601-9123-bac029e87ce0"
      },
      "source": [
        "brand + ' ' + str(ram) + 'GB'"
      ],
      "execution_count": 31,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            },
            "text/plain": [
              "'Apple 4GB'"
            ]
          },
          "metadata": {},
          "execution_count": 31
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "rhZuvfjORCEh"
      },
      "source": [
        "## 1.2 Data Structures\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3qxT-ewKRNhU"
      },
      "source": [
        "**MobiWorld store has provided a snapshot of the details of mobile phones sold by them.**\n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "jyuWMd1kT8oE"
      },
      "source": [
        "| Brand | RAM (in GB) | Memory (in GB) | Price (in dollars) |\n",
        "| --- | --- | --- | --- |\n",
        "| Apple | 4 | 128 | 900 |\n",
        "| Samsung | 12 | 128 | 899 |\n",
        "| LG | 8 | 64 | 600 |\n",
        "| Apple | 8 | 128 | 1000 |\n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "OUF9q0yGUdKP"
      },
      "source": [
        "We know how to create a variable to store the brand name."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "VCc3NBUoUbew",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "71e6a3ae-ce53-46f2-fa1b-8e3845db410d"
      },
      "source": [
        "Brand = 'Apple'\n",
        "print(Brand)"
      ],
      "execution_count": 32,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Apple\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "X1G0u69v4YKD"
      },
      "source": [
        "#### List"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "N5KIeBCPUxlY"
      },
      "source": [
        "Let's create a variable that will store all the brand names given in the above table. This can be achieved using the 'list' data struture in Python. \n",
        "\n",
        "Lists are used to store the data items inside square brackets [] where each data item is separated by a comma (,)"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "NdRGH5VVULgp",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "37c65129-0eef-4b40-c244-8e4376d5ea6c"
      },
      "source": [
        "# create a list \n",
        "brand_list = ['Apple', 'Samsung', 'LG', 'Apple']\n",
        "brand_list"
      ],
      "execution_count": 33,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['Apple', 'Samsung', 'LG', 'Apple']"
            ]
          },
          "metadata": {},
          "execution_count": 33
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Gs5hLI-zVybq",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "5c827bb9-5d57-4dde-a8b0-c6a633e7aa33"
      },
      "source": [
        "# check the type of the variable 'brand_list'\n",
        "type(brand_list)"
      ],
      "execution_count": 34,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "list"
            ]
          },
          "metadata": {},
          "execution_count": 34
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "f8k9SsafaAh5"
      },
      "source": [
        "Let's create lists for other attributes as well."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "pz296Fu9aKkD"
      },
      "source": [
        "ram_list = [4, 12, 8, 8]\n",
        "storage_list = [128, 128, 64, 128]\n",
        "price_list = [900, 899, 600, 1000]"
      ],
      "execution_count": 35,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "uyvz9uRCa8Vw",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "7e5529e6-9261-433e-d101-80878bfb1047"
      },
      "source": [
        "# let's print the lists we created\n",
        "print('RAM List:', ram_list)\n",
        "print('Storage List:', storage_list)\n",
        "print('Price List:', price_list)"
      ],
      "execution_count": 36,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "RAM List: [4, 12, 8, 8]\n",
            "Storage List: [128, 128, 64, 128]\n",
            "Price List: [900, 899, 600, 1000]\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "gcUOproLbUrd"
      },
      "source": [
        "Now, we have created lists for all attributes with the provided data. There are various operations that can be performed on lists to extract information from the data. Let's understand a few important methods by answering some questions."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "XZ-I7h-mcTfQ"
      },
      "source": [
        "Q. How many records are stored in the list brand_list?"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "8bMPW9ltctr-"
      },
      "source": [
        "\n",
        "\n",
        "* len() is an in-built function in Python that provides the count of elements inside a list. In-built functions are functions that are already defined in the Python framework to perform a task.\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "C_aMKnD9cn29",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "9d05bbf7-bc7e-47d7-c4b0-628ab4593cdd"
      },
      "source": [
        "len(brand_list)"
      ],
      "execution_count": 37,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "4"
            ]
          },
          "metadata": {},
          "execution_count": 37
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ucTw2ifG-glr"
      },
      "source": [
        "We have 4 records "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6z_HEP48dBfH"
      },
      "source": [
        "Q. Find the minimum and maximum price among the mobile phones sold by the store."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "UqCrWx7d_QD-"
      },
      "source": [
        "* min() and max() are in-built functions in Python that calculates the minimum and maximum values among the items in a list (or some other data types)."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Jlj1uxuNd-hw",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "8fd0e9d9-1445-4d39-d5fd-77c58eb83d79"
      },
      "source": [
        "# minimum price\n",
        "min_price = min(price_list)\n",
        "print('The minimum price is $' + str(min_price))\n",
        "# maximum price\n",
        "max_price = max(price_list)\n",
        "print('The maximum price is $' + str(max_price))"
      ],
      "execution_count": 38,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The minimum price is $600\n",
            "The maximum price is $1000\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "aIihYl6veE6t"
      },
      "source": [
        "* The minimum and maximum prices are \\$600 and $1000 respectively. \n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "XNuquyGf5CPM"
      },
      "source": [
        "As a list may contain a large number of items in it, there should be a way to access the item that we want. This is achieved by indexing the list to access the required item.\n",
        "\n",
        "Q. Print the third item in the list ram_list."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "uqHY5ehU5HKQ"
      },
      "source": [
        "* Indexing in list is done by specifying the index inside square brackets. In python, indexing starts with 0. That is, the first item has the index 0, the second has the index 1 and so on."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_amZFVGQ5LzK",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "aef376d3-497b-4b4d-f9a8-3178c61cd997"
      },
      "source": [
        "# indexing to get the third item in ram_list\n",
        "print(ram_list[2])"
      ],
      "execution_count": 39,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "8\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "010MLnYv5RF5"
      },
      "source": [
        "Q. Print the first three items from the list price_list."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "a5WRJWAz5T3q"
      },
      "source": [
        "* We can also select a range of indices to access more than 1 item. This can be done by using a colon (:) between the start and stop index"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "31v2bdjK5fsV",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "61ef189c-e807-454f-fe90-12462daff060"
      },
      "source": [
        "# first three items in price_list\n",
        "print(price_list[0:3])"
      ],
      "execution_count": 40,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[900, 899, 600]\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Y-UXUhxZ5jPL"
      },
      "source": [
        "Notice that in such an indexing, the output includes the item at the start index (index 0) but excludes the item at the stop index (index 3). The index [0:3] has included the items at indices 0, 1 and 2"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "IQ7KaeJE5m7U"
      },
      "source": [
        "Q. Print the last item in the list brand_list."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "KSsQP0g75p2K"
      },
      "source": [
        "* The last item can also be accessed using its index. But, if the list is too large, counting the index for the last item may not be the best way. Here's how the last item can be accessed for any list."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "NwovAGAn5rzu",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "3fa51aa1-662c-48a7-e1c5-5a618a5acef1"
      },
      "source": [
        "# last item in brand_list\n",
        "print(brand_list[-1])"
      ],
      "execution_count": 41,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Apple\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "f1Omoi3ThWZS"
      },
      "source": [
        "The Store finds out that for the last record in the data, the brand name provided was not correct. \n",
        "\n",
        "Q. Remove the last element from the list brand_list."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3PLiR1eriB0r"
      },
      "source": [
        "* pop() is a list method that removes the item at the given index and returns the removed item . If the index is not specified, by default, it removes the last element. To confirm we can check the list again."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GLU8d4VLhgBo",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "d5bcf8cb-8ed1-4e68-c9ec-5def63f622d2"
      },
      "source": [
        "brand_list.pop()"
      ],
      "execution_count": 42,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            },
            "text/plain": [
              "'Apple'"
            ]
          },
          "metadata": {},
          "execution_count": 42
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GKlrRebCkcSl",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "3897ee66-6568-4dc5-9ad8-5751c7309c35"
      },
      "source": [
        "brand_list"
      ],
      "execution_count": 43,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['Apple', 'Samsung', 'LG']"
            ]
          },
          "metadata": {},
          "execution_count": 43
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wq_76ZPjkdpN"
      },
      "source": [
        "As we can see the last element got removed. Now, the Store informs that the correct brand name should be \"Motorola'.\n",
        "\n",
        "Q. Insert 'Motorola' to the list brand_list\n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YkMJ6BX86fup"
      },
      "source": [
        "* The append() method adds a single item to an existing list."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "OWRzQJ5FmJMq",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "420ce930-77c6-44cb-e5f2-f17dcd188367"
      },
      "source": [
        "brand_list.append('Motorola')\n",
        "brand_list"
      ],
      "execution_count": 44,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['Apple', 'Samsung', 'LG', 'Motorola']"
            ]
          },
          "metadata": {},
          "execution_count": 44
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "brand_list[3] = 'Apple'\n",
        "print(brand_list)\n"
      ],
      "metadata": {
        "id": "qxGjoIqOAm-l",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "494c820b-d60c-4880-b4db-f0db13ffe338"
      },
      "execution_count": 45,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "['Apple', 'Samsung', 'LG', 'Apple']\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "brand_list[3] = 'Motorola'\n",
        "brand_list"
      ],
      "metadata": {
        "id": "ogGGnKahAzr8",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "224569fb-d03f-4d0b-d21a-458b08a70440"
      },
      "execution_count": 46,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['Apple', 'Samsung', 'LG', 'Motorola']"
            ]
          },
          "metadata": {},
          "execution_count": 46
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "EwtvxH6HmLvQ"
      },
      "source": [
        "We have succesfully corrected the list now."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "rlcQJDLlFUuz"
      },
      "source": [
        "#### Tuple"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cCG1aiFWFXcY"
      },
      "source": [
        "Now that you have learned about lists, you know that data can be modified and altered in a list, making it a mutable data structure. Sometimes, you might want to store data which should not be altered, for example storage. The storage in a mobile phone is in terms of powers of 2, that is, 32 GB, 64 GB, 128 GB, etc. You do not want to alter the number 32 and change it to 30.\n",
        "\n",
        "Q. Store the storage specifications 32/64/128/256 as an immutable variable."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "asSlUBP6Iep3",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "43d33f87-2e62-434a-90b0-d94f8f68047f"
      },
      "source": [
        "storage = (32,64,128,256)\n",
        "print(storage)"
      ],
      "execution_count": 47,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "(32, 64, 128, 256)\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "5HOrggg8JBBx",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "b29fadd6-9955-46ce-93c8-ec45cb3bcd60"
      },
      "source": [
        "type(storage)"
      ],
      "execution_count": 48,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "tuple"
            ]
          },
          "metadata": {},
          "execution_count": 48
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "RkusDTP8I4FJ"
      },
      "source": [
        "* The above data structure structure is called a tuple. A tuple in Python is similar to a list. The difference between the two is that unlike lists we cannot change the elements of a tuple once it is assigned. "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "PXRJO7GCJqp3"
      },
      "source": [
        "Indexing in tuple is similar to indexing in lists. \n",
        "\n",
        "Q. Print the second item in the tuple **storage**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MPV67Nb7J1xC",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "25ed3947-a421-4754-86ef-ebda2a3462a6"
      },
      "source": [
        "print(storage[1])"
      ],
      "execution_count": 49,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "64\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "4DYux3LMMib_"
      },
      "source": [
        "Let's try changing the second item to 60 and see if it works."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dBOc6JBkMnjD",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 183
        },
        "outputId": "34a4dbea-4302-4698-bb06-284584ac5304"
      },
      "source": [
        "# try changing an item in a tuple\n",
        "storage[1]=60"
      ],
      "execution_count": 50,
      "outputs": [
        {
          "output_type": "error",
          "ename": "TypeError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-50-7b98a1c9ad53>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m# try changing an item in a tuple\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mstorage\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m60\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        ""
      ],
      "metadata": {
        "id": "EVpfK94zAjgu"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "U_JDEPZmMwbn"
      },
      "source": [
        "As can be seen from the TypeError, items cannot be altered in a tuple."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "kRjiRzYl9Xuy"
      },
      "source": [
        "### Dictionary"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2sGaZr6V6xz-"
      },
      "source": [
        "Lists are great for storing data for a single attribute. But, we might want to add more information about the items in a variable. Suppose the store wants to store the attributes **brand, ram, storage,** and **price** in a single variable.\n",
        "\n",
        "Q. Store the attributes of an Apple iPhone (4GB, 128GB) of price of $800 in a single variable."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "4cwMCttF6yfe",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "b7f9db90-65df-4e57-ea10-a196400d7313"
      },
      "source": [
        "# creating a dictionary\n",
        "attributes = {\n",
        "    'Brand':'Apple', \n",
        "    'RAM (in GB)':4, \n",
        "    'Storage (in GB)':128, \n",
        "    'Price (in $)':800\n",
        "    }\n",
        "print(attributes)"
      ],
      "execution_count": 51,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "{'Brand': 'Apple', 'RAM (in GB)': 4, 'Storage (in GB)': 128, 'Price (in $)': 800}\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MRBEI4Cq6yon",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "d5f6a9fc-dce3-41af-b66c-45946ca238e6"
      },
      "source": [
        "type(attributes)"
      ],
      "execution_count": 52,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "dict"
            ]
          },
          "metadata": {},
          "execution_count": 52
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "LZNjeZOl6yuX"
      },
      "source": [
        "* The above data structure is called a dictionary. Dictionaries are used to store data values in key:value pairs. Dictionaries are written with curly brackets, and have keys and values"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "tl9LAqoH6yzS"
      },
      "source": [
        "Q. Extract the price from the dictionary attributes."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CzHdoQlB6y3v",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "04e32d3b-3611-4730-de9c-817c12edee58"
      },
      "source": [
        "# extract information from dictionary\n",
        "print(attributes['Price (in $)'])"
      ],
      "execution_count": 53,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "800\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6NIP3jxK6y74"
      },
      "source": [
        "* For the above pair, 'Price (in $)' is the key and 800 is the value. \n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "PCVO_dye6y_7"
      },
      "source": [
        "Dictionary items are ordered, changeable, and does not allow duplicates.\n",
        "\n",
        "Q. Change the price in attributes to 900"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TKkiBcId6zEe",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "d1147b12-0774-4bff-feac-c0d7adceb2a2"
      },
      "source": [
        "attributes['Price (in $)'] = 900\n",
        "print(attributes)"
      ],
      "execution_count": 54,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "{'Brand': 'Apple', 'RAM (in GB)': 4, 'Storage (in GB)': 128, 'Price (in $)': 900}\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "45krqXL96zIl"
      },
      "source": [
        "Now, that you have learned how to create a dictionary, let's store data for multiple mobile phones in it. The values in a dictionary can also be a list to store information for more than one product.\n",
        "\n",
        "Q. Create a dictionary **products** for storing the attributes of 4 different mobile phones."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "NsoJ2cyA6zMw",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "5e302147-529f-4080-c010-88f1df3ed4d8"
      },
      "source": [
        "# creating a dictionary for storing data.\n",
        "products = {\n",
        "    'Brand':brand_list, \n",
        "    'RAM (in GB)':ram_list, \n",
        "    'Storage (in GB)':storage_list, \n",
        "    'Price (in $)':price_list\n",
        "    }\n",
        "print(products)"
      ],
      "execution_count": 55,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "{'Brand': ['Apple', 'Samsung', 'LG', 'Motorola'], 'RAM (in GB)': [4, 12, 8, 8], 'Storage (in GB)': [128, 128, 64, 128], 'Price (in $)': [900, 899, 600, 1000]}\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "kKJpHALM7PXY"
      },
      "source": [
        "Using a dictionary, we have stored a lot of information in a single variable."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "hoJ8bnAC7O1L"
      },
      "source": [
        "Q. Extract the keys and values from the dictionary **products**"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "H49Xs3EL7V4T"
      },
      "source": [
        "* keys() and values() are methods of a dictionary to extract the lists of dictionary keys and dictionary values respectively."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "n6neMTb47YGT",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "5367aa69-c105-4d98-da86-011bdefb3ba4"
      },
      "source": [
        "# keys of a dictionary\n",
        "keys = products.keys()\n",
        "print('The keys of the dictionary are :\\n',keys)\n",
        "# values of a dictionary\n",
        "values = products.values()\n",
        "print('The values of the dictionary are :\\n', values)"
      ],
      "execution_count": 56,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The keys of the dictionary are :\n",
            " dict_keys(['Brand', 'RAM (in GB)', 'Storage (in GB)', 'Price (in $)'])\n",
            "The values of the dictionary are :\n",
            " dict_values([['Apple', 'Samsung', 'LG', 'Motorola'], [4, 12, 8, 8], [128, 128, 64, 128], [900, 899, 600, 1000]])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "products['RAM (in GB)'][1]"
      ],
      "metadata": {
        "id": "lTsHd_OBGhIQ",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "23d034b0-6792-45c1-ed0c-8541ef2f9e25"
      },
      "execution_count": 57,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "12"
            ]
          },
          "metadata": {},
          "execution_count": 57
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "I3qwY_iVxkuX"
      },
      "source": [
        "## 1.3 Conditional Statements"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cQo-OvN_ygtR"
      },
      "source": [
        "Suppose a customer is planning to buy a mobile phone but has a limited budget. Thus, his decision to buy is based on the condition that the price comes under his budget. Let's say his budget is $600.\n",
        "\n",
        "Q. Write a code in Python that prints whether the customer can buy the iPhone or not based on his budget."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qg2mxm6C2VEe"
      },
      "source": [
        "Sometimes we want to execute a block of code based on a particular condition.\n",
        "In these types of situations, we write conditional statements. \n",
        "\n",
        "The if-else statement in Python can be used for decision-making. The general syntax of an if-else statement is:\n",
        "\n",
        "```\n",
        "if (test expression):\n",
        "    Body of if\n",
        "else:\n",
        "    Body of else\n",
        "```\n",
        "\n",
        "Python is a tabbed based language, so we need to be VERY careful about tabs!!!\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "V8z790Jc0pNQ",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "256aed9f-dbb9-4de1-8588-6a6dba4ae083"
      },
      "source": [
        "# define the budget price\n",
        "budget = int(input('Enter your budget(in dollars): '))\n",
        "\n",
        "# if-else statement\n",
        "if price <= budget:\n",
        "  print('Congrats! You can buy the Iphone')\n",
        "else:\n",
        "  print('Sorry! The mobile price is more than your budget')"
      ],
      "execution_count": 58,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Enter your budget(in dollars): 100\n",
            "Sorry! The mobile price is more than your budget\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "dUm645mL3xfe"
      },
      "source": [
        "If there are multiple conditions, we may use another conditional statement called if-elif-else statement. The general syntax of the if-elif-else statement is:\n",
        "\n",
        "```\n",
        "if (test expression):\n",
        "    Body of if\n",
        "elif (test expression):\n",
        "    Body of elif\n",
        "else: \n",
        "    Body of else\n",
        "```\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mBwaTNNJ97yi"
      },
      "source": [
        "Q. Suppose the price of the 32 GB, 64 GB, and 128 GB iPhones are \\$600, \\$700, and \\$900 respectively. Write a conditional statement to print the price based on the internal storage of the phone."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QdJzMWMn_QTD",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "3e12980f-e011-4cbe-b6e3-66d7252651ee"
      },
      "source": [
        "Memory = int(input('Enter the memory: '))\n",
        "\n",
        "if Memory == 32:\n",
        "  print('The price of the phone is $600')\n",
        "elif Memory == 64:\n",
        "  print('The price of the phone is $700')\n",
        "elif Memory ==128:\n",
        "  print('The price of the phone is $900')\n",
        "else:\n",
        "  print('Please enter a valid memory requirement')"
      ],
      "execution_count": 59,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Enter the memory: 64\n",
            "The price of the phone is $700\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        ""
      ],
      "metadata": {
        "id": "5FdEMXl_vs69"
      },
      "execution_count": 59,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "crVFfqHF_7Qj"
      },
      "source": [
        "## 1.4 Looping Statements\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "02kfQy3pKSLz"
      },
      "source": [
        "\n",
        "\n",
        "\n",
        "Suppose the store wants to check the price of the Apple iPhone (4GB, 128GB) after providing 5%, 10%, 15%, and 20% discounts respectively. Instead of calculating the discounted prices multiple times, looping statements can be used to achieve this.\n",
        "\n",
        "Q. Write a code in Python that prints the discounted price for each of the above-mentioned discounts.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "XimtS0PyirT9"
      },
      "source": [
        "Before jumping into the concept of looping, let's have a look at the range() function in Python.\n",
        "\n",
        "The range() method returns an immutable sequence of numbers between the given start integer to the stop integer."
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "print(range(6))"
      ],
      "metadata": {
        "id": "lFAxNkQeJ6Wi",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "fc08fad2-4092-428f-915d-ddc0d52c1aab"
      },
      "execution_count": 60,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "range(0, 6)\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "print(list(range(6)))"
      ],
      "metadata": {
        "id": "wdUJOuOSL7YZ",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "d3d66e58-d381-4942-e197-bcd613efe41d"
      },
      "execution_count": 61,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[0, 1, 2, 3, 4, 5]\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "print(list(range(2,6)))"
      ],
      "metadata": {
        "id": "vtLslStgL-cY",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "5f78c19a-e08a-4431-d7ce-c6268b06b38f"
      },
      "execution_count": 62,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[2, 3, 4, 5]\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "btIlmzGVmgmV",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "38e046d1-2bc4-47ef-dd69-84c96fa5515e"
      },
      "source": [
        "print(list(range(6, 14, 2)))"
      ],
      "execution_count": 63,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[6, 8, 10, 12]\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wColSzouLhq7"
      },
      "source": [
        "Loops are used in Python to iterate over a sequence.\n",
        "\n",
        "The syntax of the 'for loop' is:\n",
        "\n",
        "```\n",
        "for iterator_var in sequence:\n",
        "    statements(s)\n",
        "```\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_1yuJc2JAhqD",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "6c190a85-9c1a-4286-aeb9-acb60e5dfd08"
      },
      "source": [
        "# store the price (in dollars) of the mobile in variable 'Price'.\n",
        "price = 900\n",
        "# start the for loop\n",
        "for i in range(5, 21, 5):\n",
        "  # calculate the discount amount\n",
        "  discount = price * (i / 100)\n",
        "  # calculate the discounted price\n",
        "  discounted_price = price - discount\n",
        "  # print the discounted price\n",
        "  print('The price after providing ', i, ' percent discount is $', discounted_price,sep='')"
      ],
      "execution_count": 64,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The price after providing 5 percent discount is $855.0\n",
            "The price after providing 10 percent discount is $810.0\n",
            "The price after providing 15 percent discount is $765.0\n",
            "The price after providing 20 percent discount is $720.0\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "VtgR0jG1vuO7"
      },
      "source": [
        "We can also use the while loop to iterate over a sequence. The syntax of the 'while loop' is:\n",
        "\n",
        "```\n",
        "while condition:\n",
        "    statements(s)\n",
        "```\n",
        "\n",
        "Let's try to solve the above question using 'while' loops."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "9PYkcD-XQKfu",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "42103cbf-15a4-4c8d-d092-1af3040f7fb4"
      },
      "source": [
        "# store the price (in dollars) of the mobile in variable 'Price'.\n",
        "Price = 900\n",
        "# set the value of i to 5\n",
        "i = 5\n",
        "# start the while loop\n",
        "while i <= 20:\n",
        "  # calculate the discount amount\n",
        "  discount = Price * (i / 100)\n",
        "  # calculate the discounted price\n",
        "  discounted_price = Price - discount\n",
        "  # print the discounted price\n",
        "  print('The price after providing ',i, ' percent discount is $', discounted_price,sep='')\n",
        "  # increase the value of i by 5\n",
        "  i += 5"
      ],
      "execution_count": 65,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The price after providing 5 percent discount is $855.0\n",
            "The price after providing 10 percent discount is $810.0\n",
            "The price after providing 15 percent discount is $765.0\n",
            "The price after providing 20 percent discount is $720.0\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "i"
      ],
      "metadata": {
        "id": "sAWSbODZWds_",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "67a35ab6-8867-4c11-830f-b7aef3d5bba6"
      },
      "execution_count": 66,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "25"
            ]
          },
          "metadata": {},
          "execution_count": 66
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 1.5 List Comprehensions"
      ],
      "metadata": {
        "id": "fRrO-BOOeUCE"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "MobiWorld has decided to provide an instant discount of 5% on all their products during the upcoming sale. We want to check the discounted prices of the products.\n",
        "\n",
        "We already have the `price_list` with us. Let's use it to get the discounted prices."
      ],
      "metadata": {
        "id": "sBIOrOMSzXl9"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "One way of creating a discounted price list is by looping over the elements of `price_list`, subtracting the discount from the price, and adding it one at a time to a new list `discounted_price_list`."
      ],
      "metadata": {
        "id": "4q_35zrET3LJ"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "discounted_price_list=[]\n",
        "\n",
        "for x in price_list:\n",
        "  discounted_price = x - (x*(5/100))\n",
        "  discounted_price_list.append(discounted_price)\n",
        "\n",
        "print(discounted_price_list)"
      ],
      "metadata": {
        "id": "DahV8ZZcebRV",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "0ffbb97b-daf3-4d9c-dcce-61b57de2cacb"
      },
      "execution_count": 67,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[855.0, 854.05, 570.0, 950.0]\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "An equivalent way of obtaining the same result is by using **list comprehensions**.\n",
        "\n",
        "* List comprehension is a type of control structure for creating a list from an existing iterable (like tuples, strings, arrays, lists, etc).\n",
        "* They offer a shorter and more appealing syntax and are often faster than explicit for loops in creating a list from an existing iterable."
      ],
      "metadata": {
        "id": "F0iCJHIV1cx_"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "discounted_price_list = [x - (x*(5/100)) for x in price_list]\n",
        "print(discounted_price_list)"
      ],
      "metadata": {
        "id": "2rIb7zzcxTVI",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "4ba54a65-0ccc-437d-db82-125fe5df63e3"
      },
      "execution_count": 68,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[855.0, 854.05, 570.0, 950.0]\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "Let's breakdown the syntax of the above list comprehension. There are three parts:\n",
        "1. `[ ]`: The outer square brackets tells that we are creating a list\n",
        "2. `x-(x*(5/100)`: The expression to evaluate or the computation to perform\n",
        "3. `for x in price_list`: The iterable from which elements (x) will be fetched"
      ],
      "metadata": {
        "id": "0g10KPzb2hH1"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Customers often want to check whether any of the discounted prices during the sale are within their budget.\n",
        "\n",
        "Let's help the store display the same based on the budget mentioned by the customer by comparing the discounted price with the budget for each of the four mobile phone prices."
      ],
      "metadata": {
        "id": "ePfWC4q44WBj"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# asking for customer's budget\n",
        "budget = int(input('Enter your budget(in dollars): '))\n",
        "\n",
        "# creating a list of Yes/No based on budget and discounted prices\n",
        "within_budget = ['Yes' if x <= budget else 'No' for x in discounted_price_list]\n",
        "print(within_budget)"
      ],
      "metadata": {
        "id": "Pg0Ws8qz36Ce",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "ce7becf2-2ee2-4022-b627-523c1eb61569"
      },
      "execution_count": 69,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Enter your budget(in dollars): 500\n",
            "['No', 'No', 'No', 'No']\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "To get more clarity on the way the list comprehension syntax is formulated, we can expand the list comprehension to the usual for and if statements and think of this in a reversed way."
      ],
      "metadata": {
        "id": "lU5qWotf5EjH"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "within_budget = []\n",
        "\n",
        "for x in discounted_price_list:\n",
        "  if x <= budget:\n",
        "    within_budget.append('Yes')\n",
        "  else:\n",
        "    within_budget.append('No')\n",
        "\n",
        "print(within_budget)"
      ],
      "metadata": {
        "id": "Q-bj32zx5h3z",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "a008b3ec-7264-41c7-dc41-c88875ce12e2"
      },
      "execution_count": 70,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "['No', 'No', 'No', 'No']\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xEPReYdxm-E5"
      },
      "source": [
        "## 1.6 Functions in Python"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "XsVOy7oaoSXM"
      },
      "source": [
        "**What is a Function in Python?**\n",
        "\n",
        "In Python, a function is a block of instructions that performs a specific task.\n",
        "\n",
        "We have already seen a few functions in python.  min and max were functions that found the minimum and maximum numbers in a list!\n",
        "\n",
        "In Python, we can also define our own functions! We don't have to rely on the ones that are already there.\n",
        "\n",
        "Functions break the program into modular chunks which can be reused later. Functions are used to make the program more organized and manageable.\n",
        "\n",
        "\n",
        "**Syntax of a function**\n",
        "\n",
        "Functions that users define themselves to a particular task are referred to as user-defined functions.\n",
        "\n",
        "```\n",
        "def function_name(parameters):\n",
        "\t'''explain what a function does'''\n",
        "\tstatement(s)\n",
        "```\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "kMUsQDMVpgHh"
      },
      "source": [
        "Let's say the store wants to market the Apple iPhone by displaying its attributes to each customer.\n",
        "\n",
        "Q. Write a function in Python that displays the attributes of the Apple iPhone."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2qdL41zapfT5"
      },
      "source": [
        "# write the function\n",
        "def display_iphone_attributes():\n",
        "    \"\"\"\n",
        "    This function displays\n",
        "    the stored attributes of\n",
        "    the Apple iPhone\n",
        "    \"\"\"\n",
        "    # store the price (in dollars) of the mobile in variable 'price'\n",
        "    price = 900\n",
        "    # store the RAM (in GB) of the mobile in variable 'ram'.\n",
        "    ram = 4\n",
        "    # store the internal storage (in GB) of the mobile in variable 'storage'.\n",
        "    storage = 128\n",
        "    # display the details\n",
        "    print('The Apple iPhone has ', ram, ' GB RAM and ', storage, ' GB internal storage and it costs $', price, sep='')"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "8SQoJ4wWr-1g"
      },
      "source": [
        "**How to call a function in python?**\n",
        "\n",
        "Once the function is defined, we can simply call the function by writing the function name with appropriate parameters. The function definition must always be written before the function call. Else, we will get an error."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qmSi4POvsYTM"
      },
      "source": [
        "# call the function\n",
        "display_iphone_attributes()"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "8bKo7D3JtjlK"
      },
      "source": [
        "**How to write a Python function with arguments?**\n",
        "\n",
        "In Python, you can also define a function that takes a variable number of arguments. Let's try an example!\n",
        "\n",
        "Q. Write a function in Python that displays the attributes of a phone.\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "do-AAwmitijp"
      },
      "source": [
        "# write the function\n",
        "def display_phone_attributes(brand, price, ram, storage):\n",
        "    \"\"\"\n",
        "    This function displays\n",
        "    the stored attributes of\n",
        "    any phone\n",
        "    \"\"\"\n",
        "    # display the details\n",
        "    print('The ', brand, ' phone has ', ram, ' GB RAM and ', storage,' GB internal storage and it costs $',price,sep='')"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YHqgx5GWwZGT"
      },
      "source": [
        "# call the function\n",
        "display_phone_attributes('samsung', 899, 12, 128)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Dpqah3c3xcuO"
      },
      "source": [
        "Since we have called the function with the appropriate number of arguments, it runs smoothly without any error. The interpreter will show an error message in case we call it with a different number of arguments.\n",
        "\n",
        "Let's try calling the function with 3 arguments."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "sLwV4-39xzDA"
      },
      "source": [
        "# call the function with 3 arguments\n",
        "display_phone_attributes('samsung', 899, 12)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "es8xsN4dx8wG"
      },
      "source": [
        "**What is a return statement?**\n",
        "\n",
        "The return statement is used to exit a function and also returns the output.\n",
        "\n",
        "Q. Write a function in Python that takes the discount percentage as input and returns the discounted price of an Apple iPhone."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gHOoGYQzyjYw"
      },
      "source": [
        "# write the function\n",
        "def dis_price(discount):\n",
        "    \"\"\"\n",
        "    This function takes the discount \n",
        "    percentage as input and \n",
        "    returns the discounted price of Apple iPhone\n",
        "    \"\"\"\n",
        "    # store the price (in dollars) of the mobile in variable 'price'\n",
        "    price = 900\n",
        "    # calculate the price after discount\n",
        "    discounted_price = price - price * (discount / 100)\n",
        "    # return the discounted price\n",
        "    return discounted_price"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kfxk0YnjzIdu"
      },
      "source": [
        "# call the function with discount = 10%\n",
        "dp = dis_price(10)\n",
        "dp"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_IPo7Bjiz7T0"
      },
      "source": [
        "In Python, lambda function are functions a different way to define a function \n",
        "\n",
        "* User-defined functions are defined using the def keyword, whereas lambda functions are defined using the lambda keyword.\n",
        "* We generally use them when we require an anonymous function for a small task\n",
        "* We cannot use a return statement with lambda functions.\n",
        "\n",
        "Let's try to get the discounted price using lambda function."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DggmBW-X0xxa"
      },
      "source": [
        "# lambda functions\n",
        "dis_price_lambda = lambda discount : 900 - ( 900 * (discount / 100) ) "
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0ptZLkjR1ER6"
      },
      "source": [
        "# call the function with discount = 10%\n",
        "dis_price_lambda(10)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 1.7 \\*args and \\**kwargs"
      ],
      "metadata": {
        "id": "JE2FLBCIejeA"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "A customer has placed an order for 5 mobile phones with MobiWorld. The store wants to generate the total amount for the order.\n",
        "\n",
        "We can define a function with 5 arguments (one each for the price of the mobile phone ordered) to compute the total amount."
      ],
      "metadata": {
        "id": "DssVB5yJiDpe"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def total_amount(price1, price2, price3, price4, price5):\n",
        "    \"\"\"\n",
        "    This function takes the price of five phones ordered\n",
        "    and returns the total order amount.\n",
        "    \"\"\"\n",
        "    # computing the total order amount\n",
        "    total = price1 + price2 + price3 + price4 + price5\n",
        "\n",
        "    # return the total amount\n",
        "    return total"
      ],
      "metadata": {
        "id": "QWd7asLjivuh"
      },
      "execution_count": 71,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "print('Total order amount:', total_amount(700, 599, 650, 900, 820))"
      ],
      "metadata": {
        "id": "RujDjojrkGBk",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "b1706933-2c3e-4de9-d9c6-e5c6eb0f4a1d"
      },
      "execution_count": 72,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Total order amount: 3669\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "This works as we have a small number of items in the order placed. What if the customer decides to add 5 more phones to his order? It will become tedious to keep adding an argument to the function for each new addition.\n",
        "\n",
        "* In some cases, we might not even want any constraints on the number of arguments for the function."
      ],
      "metadata": {
        "id": "nswSW0-9k7gz"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Python allows us flexibility in terms of the number of arguments passed to a function by using \\*args.**"
      ],
      "metadata": {
        "id": "yCj_GaLAgpLn"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def total_amount(*args):\n",
        "    \"\"\"\n",
        "    This function takes the prices of phones ordered\n",
        "    and returns the total order amount.\n",
        "    \"\"\"\n",
        "    total = 0\n",
        "    # computing the total order amount\n",
        "    for arg in args:\n",
        "        total += arg\n",
        "\n",
        "    # return the total amount\n",
        "    return total"
      ],
      "metadata": {
        "id": "Kp20hXTbel28"
      },
      "execution_count": 73,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "Let's compute the total amount for 5 phones."
      ],
      "metadata": {
        "id": "iotLTjjAnehn"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print('Total order amount:', total_amount(700, 599, 650, 900, 820))"
      ],
      "metadata": {
        "id": "QTkUyHYJnc0I",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "407ac174-7ed6-4d34-d72e-f1d63fbb4f4f"
      },
      "execution_count": 74,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Total order amount: 3669\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "Now, let's compute the total amount for 10 phones."
      ],
      "metadata": {
        "id": "FWyaI_WqnriO"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print('Total order amount:', total_amount(700, 599, 650, 900, 820, 630, 520, 799, 999, 840))"
      ],
      "metadata": {
        "id": "2ZsZt-FLnxcp",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "0837e21a-84fd-47c8-c3a5-273e26f6a1c1"
      },
      "execution_count": 75,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Total order amount: 7457\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "We can also use any other text in place of *args*."
      ],
      "metadata": {
        "id": "DMovmVM2nHVR"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def total_amount(*prices):\n",
        "    \"\"\"\n",
        "    This function takes the prices of phones ordered\n",
        "    and returns the total order amount.\n",
        "    \"\"\"\n",
        "    total = 0\n",
        "    # computing the total order amount\n",
        "    for price in prices:\n",
        "        total += price\n",
        "\n",
        "    # return the total amount\n",
        "    return total"
      ],
      "metadata": {
        "id": "ylVGHrXfnHKR"
      },
      "execution_count": 76,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "print('Total order amount:', total_amount(700, 599, 650, 900, 820, 630, 520, 799, 999, 840))"
      ],
      "metadata": {
        "id": "RKzMj2jrnHIC",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "fd480e47-fafa-4451-af18-95548b2a8435"
      },
      "execution_count": 77,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Total order amount: 7457\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "Till now, the arguments we have passed to our functions have been declared by names only, like brand, ram, price1. These types of arguments are called **positional arguments**.\n",
        "\n",
        "Another type of argument in Python is **called keyword argument**, which is declared using both a name and a default value."
      ],
      "metadata": {
        "id": "V3o5ByDooLFN"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Let us consider the festive season sale, where the store is offering a discount of 5% on all its products. Outside the sale period, there will be no discount for the products.\n",
        "\n",
        "Let's create a new function to compute the total discounted price for an order of one or more phones placed by a customer."
      ],
      "metadata": {
        "id": "tIDDR7GqpRzj"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def total_discounted_amount(*prices, discount=0.0):\n",
        "    \"\"\"\n",
        "    This function takes the prices of phones ordered\n",
        "    and the discount percentage\n",
        "    and returns the total discounted order amount.\n",
        "    \"\"\"\n",
        "    total = 0\n",
        "    # computing the total order amount\n",
        "    for price in prices:\n",
        "        total += price\n",
        "\n",
        "    total_discounted_price = total - discount*total\n",
        "    \n",
        "    # return the total amount\n",
        "    return total_discounted_price"
      ],
      "metadata": {
        "id": "KwFVie38nHFl"
      },
      "execution_count": 78,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "print('Total discounted order amount:', total_discounted_amount(700, 599, 650, 900, 820, 630, 520, 799, 999, 840))"
      ],
      "metadata": {
        "id": "eAoxq0-arNT-",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "ac9cd419-6d38-41af-bb12-5c30d47da1ab"
      },
      "execution_count": 79,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Total discounted order amount: 7457.0\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "The discount percentage during the festive season sale will be 5%, which we can specify by setting the keyword argument *discount* to 0.05."
      ],
      "metadata": {
        "id": "e3fU3p0trmSz"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print('Total discounted order amount (during festive season):', total_discounted_amount(700, 599, 650, 900, 820, 630, 520, 799, 999, 840, discount=0.05))"
      ],
      "metadata": {
        "id": "NY1oWOAWrNR2",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "af230853-2e86-4bab-bbf0-7b97d80c7bf6"
      },
      "execution_count": 80,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Total discounted order amount (during festive season): 7084.15\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Note**: In Python, keyword arguments should be declared after the positional arguments."
      ],
      "metadata": {
        "id": "cMvR2qXc-3ZH"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def total_discounted_amount(discount=0.0, *prices):\n",
        "    \"\"\"\n",
        "    This function takes the prices of phones ordered\n",
        "    and the discount percentage\n",
        "    and returns the total discounted order amount.\n",
        "    \"\"\"\n",
        "    total = 0\n",
        "    # computing the total order amount\n",
        "    for price in prices:\n",
        "        total += price\n",
        "\n",
        "    total_discounted_price = total - discount*total\n",
        "    \n",
        "    # return the total amount\n",
        "    return total_discounted_price"
      ],
      "metadata": {
        "id": "P8jWyqxT-21L"
      },
      "execution_count": 81,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "print('Total discounted order amount (during festive season):', total_discounted_amount(discount=0.05, 700, 599, 650, 900, 820, 630, 520, 799, 999, 840))"
      ],
      "metadata": {
        "id": "cOGENuPH_Byi",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 149
        },
        "outputId": "1b14cf76-ea01-4d6c-e2cf-4e37d5043932"
      },
      "execution_count": 82,
      "outputs": [
        {
          "output_type": "error",
          "ename": "SyntaxError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-82-b566d9ac1e5b>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    print('Total discounted order amount (during festive season):', total_discounted_amount(discount=0.05, 700, 599, 650, 900, 820, 630, 520, 799, 999, 840))\u001b[0m\n\u001b[0m                                                                                                          ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m positional argument follows keyword argument\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "If we assign a value to a positional argument, it becomes a keyword argument. Since it is followed by positional arguments, we get a SyntaxError."
      ],
      "metadata": {
        "id": "9bfBORmP_B9Z"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Just like \\*args helped us remove the constraint on the number of positional arguments, \\**kwargs helps us remove the constraint on the number of keyword arguments.\n",
        "\n",
        "The \\**kwargs argument passed while calling the function must be a mapping, such as a dictionary."
      ],
      "metadata": {
        "id": "zy1c9pLdsC4I"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "MobiWorld has decided to offer a \\$5 cashback on all the products on top of the 5% discount for the last day of the festive season sale. Let's create a function to compute the customer's net spend."
      ],
      "metadata": {
        "id": "V1GvvsqZszot"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def customer_net_spend(*prices, discount=0.0, **kwargs):\n",
        "    \"\"\"\n",
        "    This function takes the prices of phones ordered,\n",
        "    the discount percentage, and any other cost additions/subtractions,\n",
        "    and returns the customer's net spend on the order.\n",
        "    \"\"\"\n",
        "    total = 0\n",
        "    # computing the total order amount\n",
        "    for price in prices:\n",
        "        total += price\n",
        "\n",
        "    total_discounted_price = total - discount*total\n",
        "\n",
        "    net_spend = total_discounted_price - kwargs['cashback']\n",
        "    \n",
        "    # return the total amount\n",
        "    return net_spend"
      ],
      "metadata": {
        "id": "FXpSsvqErNM-"
      },
      "execution_count": 83,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "additionals = {'cashback': 5}\n",
        "print('Customer net spend (during last day of festive season):', customer_net_spend(700, 599, 650, discount=0.05, **additionals))"
      ],
      "metadata": {
        "id": "EIsAtDpxvu6K",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "ab4b1c23-6ab5-45f7-e5fd-85cc0b445e6f"
      },
      "execution_count": 84,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Customer net spend (during last day of festive season): 1846.55\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "MobiWorld plans to introduce a reward-point system based on the total order amount. Reward points will be given as per the following scheme:\n",
        "\n",
        "* Total Amount >= 2000: 100 Reward Points\n",
        "* Total Amount >= 5000: 200 Reward Points\n",
        "* Total Amount >= 10000: 300 Reward Points\n",
        "\n",
        "Let's define a function that will return the total amount, net spend, and rewards points earned for the order."
      ],
      "metadata": {
        "id": "N1JbP5cP_jCR"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def order_summary(*prices, **additionals):\n",
        "    \"\"\"\n",
        "    This function takes the prices of phones ordered\n",
        "    and any other cost additions/subtractions,\n",
        "    and returns the total amount, net spend,\n",
        "    and rewards points earned for the order.\n",
        "    \"\"\"\n",
        "    total = 0\n",
        "    # computing the total order amount\n",
        "    for price in prices:\n",
        "        total += price\n",
        "\n",
        "    net_spend = total - additionals['discount']*total - additionals['cashback']\n",
        "\n",
        "    if total >= 10000:\n",
        "        reward_points = 300\n",
        "    elif total >= 5000:\n",
        "        reward_points = 200\n",
        "    elif total >= 2000:\n",
        "        reward_points = 100\n",
        "    else:\n",
        "        reward_points = 0\n",
        "    \n",
        "    # return the total amount\n",
        "    return total, net_spend, reward_points"
      ],
      "metadata": {
        "id": "1ANWNzPLDMpW"
      },
      "execution_count": 85,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "additionals = {'discount':0.05, 'cashback': 5}\n",
        "ta, ns, rp = order_summary(700, 599, 750, **additionals)\n",
        "print('Customer Order Summary:\\n', '\\nTotal Amount:', ta, '\\nTotal Discounted Amount:', ns, '\\nReward Points Earned:', rp)"
      ],
      "metadata": {
        "id": "CttK_RKoDMlA",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "f65b27e5-e0b2-4ce6-ac4a-0e195399da5c"
      },
      "execution_count": 86,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Customer Order Summary:\n",
            " \n",
            "Total Amount: 2049 \n",
            "Total Discounted Amount: 1941.55 \n",
            "Reward Points Earned: 100\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "***"
      ],
      "metadata": {
        "id": "_NZ2bn_vy6vJ"
      }
    }
  ]
}