From 1c6261aa4f37539704ee7bf04f7f9a239bcfd82a Mon Sep 17 00:00:00 2001 From: weipeng Date: Tue, 12 Oct 2021 20:43:24 -0400 Subject: [PATCH 1/4] first upload of python basics challange #1 --- python-basics-1.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 python-basics-1.py diff --git a/python-basics-1.py b/python-basics-1.py new file mode 100644 index 0000000..cea5535 --- /dev/null +++ b/python-basics-1.py @@ -0,0 +1,68 @@ +def hello_world(): + '''Prints "Hello World!".''' + print("Hello World!") + return + + +def sum(a, b): + '''Accepts 2 numbers as parameters, returns sum of a and b.''' + return a + b + + +def sub(a, b): + '''Accepts 2 numbers as parameters, returns subtraction of a and b.''' + return a - b + + +def product(a, b): + '''Accepts 2 numbers as parameters, returns product of a and b.''' + # CHALLENGE: use a for loop and your sum function to implement product + ans = 0 + for i in range(b): + ans = sum(ans, a) + return ans + + +def divide(a, b): + '''Accepts 2 numbers as parameters, returns a divided by b.''' + # only pass in numbers that are divisible for sake of implementation + # CHALLENGE: use a while loop and your sub function to implement divide + ans = 0 + while (a > 0): + a = sub(a, b) + ans += 1 + return ans + + +def root(num): + '''Accepts a number as a parameter, returns the sqrt of num.''' + # only pass in numbers that are perfect squares for sake of implementation + # leetcode easy + # CHALLENGE: do not use any built-in Python functions + if num == 0 or num == 1: + return num + ans = 1 + result = 1 + while (result < num): + ans += 1 + result = ans * ans + return ans; + + +def main(): + '''The main function is where you will test all of your functions.''' + hello_world() + print("Testing sum:") + print("EXPECTED: %d, ACTUAL: %d\n" % (5, sum(2, 3))) + print("Testing sub:") + print("EXPECTED: %d, ACTUAL: %d\n" % (5, sub(7, 2))) + print("Testing product:") + print("EXPECTED: %d, ACTUAL: %d\n" % (10, product(2, 5))) + print("Testing divide:") + print("EXPECTED: %d, ACTUAL: %d\n" % (5, divide(10, 2))) + print("Testing root:") + print("EXPECTED: %d, ACTUAL: %d\n" % (5, root(25))) + # Add any additional test cases if needed + +if __name__ == "__main__": + main() \ No newline at end of file From 472459d12515ac00dc743fe45385a819e81c087b Mon Sep 17 00:00:00 2001 From: weipeng Date: Tue, 26 Oct 2021 19:42:20 -0400 Subject: [PATCH 2/4] finished challenge #2 --- .DS_Store | Bin 0 -> 6148 bytes main2.py | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0814f895b2f86b0967f8a0cc781099e7ad71b2a7 GIT binary patch literal 6148 zcmeH~Jx;?w5QX1DibymT73E$aNV$O(g@T$3fI|UNgpnXcI(Hl!-u!?tHZ28uBh5bV z?98tG6&^2uvN_zZfd;^mZi+V>re^Er6FbRBq0+fWk0-3q;SMj8?D>Gzp5qxuyy9V0 z|A-xTSz(P!Tfg4-yKdii%x~U**!WdVot0TUwq4}_RRG*bqMux#=V@X9|7Yc6M?@V@ByAfCjbBd literal 0 HcmV?d00001 diff --git a/main2.py b/main2.py index 2f6ad21..69e9d7d 100644 --- a/main2.py +++ b/main2.py @@ -2,7 +2,7 @@ def oddOrEven(nums): '''Given an unsorted list of numbers, return a list that indicates if the value at each index is odd (0) or even (1).''' # EXAMPLE: # Given [2, 4, 5, 7, 8, 10], return [1, 1, 0, 0, 1, 1] - return [] + return [(i + 1) % 2 for i in nums] def mostOccurences(nums): @@ -10,7 +10,18 @@ def mostOccurences(nums): # Hint: use oddOrEven to test function faster # Hint: use a map # Hint: https://stackoverflow.com/questions/13098638/how-to-iterate-over-the-elements-of-a-map-in-python - return -1 + mp = {} + for k in nums: + if k in mp: + mp[k] += 1 + else: + mp[k] = 1 + max, ans = -1, 0 + for i in mp: + if max < mp[i]: + max = mp[i] + ans = i + return ans def main(): From 2aa7f205ab4d80ee6b4ec27745fa0a34a85bd170 Mon Sep 17 00:00:00 2001 From: weipeng Date: Tue, 26 Oct 2021 20:12:25 -0400 Subject: [PATCH 3/4] update challenge #1 --- .DS_Store | Bin 6148 -> 6148 bytes main.py | 25 +++++++++++++---- python-basics-1.py | 68 --------------------------------------------- 3 files changed, 20 insertions(+), 73 deletions(-) delete mode 100644 python-basics-1.py diff --git a/.DS_Store b/.DS_Store index 0814f895b2f86b0967f8a0cc781099e7ad71b2a7..51d9013a75d3374fd87f093b29b0e20fe3d1ca73 100644 GIT binary patch literal 6148 zcmeHKyH3ME5S$Gb7=t0VRzUg@T$NAR$d8gOMNwog01yiSOeBVD@%pVaI6^ zigu;FxyS7JZY+7d0A#jVT>ujRIbCsd%x1uJU46?&K66ME-Q%{ZAC^_U7*6^M!VZrDJ2r8Cv`ZBpIR!1^!flABetOlK=n! delta 148 zcmZoMXfc=|#>CJ*u~2NHo}wrt0|NsP3otO`GvqPoG9)o1G89iNRCfhQ2r(2eR5Fw> zWFSj2WHKZ(6a$qSGU$QiJ#+GtlXCKtfa(SQqk+wa%-2{pJ1{3QZD!}-=Kxv@6#33P TnP0?^kzuk8kM!mkkrm7U`3@{# diff --git a/main.py b/main.py index 379f286..cea5535 100644 --- a/main.py +++ b/main.py @@ -1,29 +1,37 @@ def hello_world(): '''Prints "Hello World!".''' + print("Hello World!") return def sum(a, b): '''Accepts 2 numbers as parameters, returns sum of a and b.''' - return 0 + return a + b def sub(a, b): '''Accepts 2 numbers as parameters, returns subtraction of a and b.''' - return 0 + return a - b def product(a, b): '''Accepts 2 numbers as parameters, returns product of a and b.''' # CHALLENGE: use a for loop and your sum function to implement product - return 0 + ans = 0 + for i in range(b): + ans = sum(ans, a) + return ans def divide(a, b): '''Accepts 2 numbers as parameters, returns a divided by b.''' # only pass in numbers that are divisible for sake of implementation # CHALLENGE: use a while loop and your sub function to implement divide - return 0 + ans = 0 + while (a > 0): + a = sub(a, b) + ans += 1 + return ans def root(num): @@ -31,7 +39,14 @@ def root(num): # only pass in numbers that are perfect squares for sake of implementation # leetcode easy # CHALLENGE: do not use any built-in Python functions - return 0; + if num == 0 or num == 1: + return num + ans = 1 + result = 1 + while (result < num): + ans += 1 + result = ans * ans + return ans; def main(): diff --git a/python-basics-1.py b/python-basics-1.py deleted file mode 100644 index cea5535..0000000 --- a/python-basics-1.py +++ /dev/null @@ -1,68 +0,0 @@ -def hello_world(): - '''Prints "Hello World!".''' - print("Hello World!") - return - - -def sum(a, b): - '''Accepts 2 numbers as parameters, returns sum of a and b.''' - return a + b - - -def sub(a, b): - '''Accepts 2 numbers as parameters, returns subtraction of a and b.''' - return a - b - - -def product(a, b): - '''Accepts 2 numbers as parameters, returns product of a and b.''' - # CHALLENGE: use a for loop and your sum function to implement product - ans = 0 - for i in range(b): - ans = sum(ans, a) - return ans - - -def divide(a, b): - '''Accepts 2 numbers as parameters, returns a divided by b.''' - # only pass in numbers that are divisible for sake of implementation - # CHALLENGE: use a while loop and your sub function to implement divide - ans = 0 - while (a > 0): - a = sub(a, b) - ans += 1 - return ans - - -def root(num): - '''Accepts a number as a parameter, returns the sqrt of num.''' - # only pass in numbers that are perfect squares for sake of implementation - # leetcode easy - # CHALLENGE: do not use any built-in Python functions - if num == 0 or num == 1: - return num - ans = 1 - result = 1 - while (result < num): - ans += 1 - result = ans * ans - return ans; - - -def main(): - '''The main function is where you will test all of your functions.''' - hello_world() - print("Testing sum:") - print("EXPECTED: %d, ACTUAL: %d\n" % (5, sum(2, 3))) - print("Testing sub:") - print("EXPECTED: %d, ACTUAL: %d\n" % (5, sub(7, 2))) - print("Testing product:") - print("EXPECTED: %d, ACTUAL: %d\n" % (10, product(2, 5))) - print("Testing divide:") - print("EXPECTED: %d, ACTUAL: %d\n" % (5, divide(10, 2))) - print("Testing root:") - print("EXPECTED: %d, ACTUAL: %d\n" % (5, root(25))) - # Add any additional test cases if needed - -if __name__ == "__main__": - main() \ No newline at end of file From fcd6b636b3e6356b84c5a0488e2ea2146315650f Mon Sep 17 00:00:00 2001 From: weipeng Date: Tue, 26 Oct 2021 20:19:28 -0400 Subject: [PATCH 4/4] update branch --- .DS_Store | Bin 6148 -> 6148 bytes data/sales_records.csv | 101 +++++++++++++++++++++++++++++++++++++++++ main3.py | 57 +++++++++++++++++++++++ solution.py | 0 solution2.py | 61 +++++++++++++++++++++++++ 5 files changed, 219 insertions(+) create mode 100755 data/sales_records.csv create mode 100644 main3.py mode change 100644 => 100755 solution.py create mode 100755 solution2.py diff --git a/.DS_Store b/.DS_Store index 51d9013a75d3374fd87f093b29b0e20fe3d1ca73..fb2649f425ead86f03556ba556c986bcaff79367 100644 GIT binary patch delta 87 zcmZoMXfc@J&&a+pU^gQp`(z#_ZBZ766oy2G5{AUG;G(>o{JeAq1_s8-CQJ=%4AwyA hvdO!c3|Ym&tPf1a+$%w>|6s7$koh3XW_FIh`~dvj8s-21 delta 60 zcmZoMXfc@J&&akhU^gQp+hiUl?aBU3wQP)^85kHeCSPJQWNihrIGBwmpJfu*?9IG~ NWnzQGW_FIh`~dGX5T^hD diff --git a/data/sales_records.csv b/data/sales_records.csv new file mode 100755 index 0000000..a3c2b74 --- /dev/null +++ b/data/sales_records.csv @@ -0,0 +1,101 @@ +Region,Country,Item Type,Sales Channel,Order Priority,Order Date,Order ID,Ship Date,Units Sold,Unit Price,Unit Cost,Total Revenue,Total Cost,Total Profit +Australia and Oceania,Tuvalu,Baby Food,Offline,H,5/28/2010,669165933,6/27/2010,9925,255.28,159.42,2533654.00,1582243.50,951410.50 +Central America and the Caribbean,Grenada,Cereal,Online,C,8/22/2012,963881480,9/15/2012,2804,205.70,117.11,576782.80,328376.44,248406.36 +Europe,Russia,Office Supplies,Offline,L,5/2/2014,341417157,5/8/2014,1779,651.21,524.96,1158502.59,933903.84,224598.75 +Sub-Saharan Africa,Sao Tome and Principe,Fruits,Online,C,6/20/2014,514321792,7/5/2014,8102,9.33,6.92,75591.66,56065.84,19525.82 +Sub-Saharan Africa,Rwanda,Office Supplies,Offline,L,2/1/2013,115456712,2/6/2013,5062,651.21,524.96,3296425.02,2657347.52,639077.50 +Australia and Oceania,Solomon Islands,Baby Food,Online,C,2/4/2015,547995746,2/21/2015,2974,255.28,159.42,759202.72,474115.08,285087.64 +Sub-Saharan Africa,Angola,Household,Offline,M,4/23/2011,135425221,4/27/2011,4187,668.27,502.54,2798046.49,2104134.98,693911.51 +Sub-Saharan Africa,Burkina Faso,Vegetables,Online,H,7/17/2012,871543967,7/27/2012,8082,154.06,90.93,1245112.92,734896.26,510216.66 +Sub-Saharan Africa,Republic of the Congo,Personal Care,Offline,M,7/14/2015,770463311,8/25/2015,6070,81.73,56.67,496101.10,343986.90,152114.20 +Sub-Saharan Africa,Senegal,Cereal,Online,H,4/18/2014,616607081,5/30/2014,6593,205.70,117.11,1356180.10,772106.23,584073.87 +Asia,Kyrgyzstan,Vegetables,Online,H,6/24/2011,814711606,7/12/2011,124,154.06,90.93,19103.44,11275.32,7828.12 +Sub-Saharan Africa,Cape Verde,Clothes,Offline,H,8/2/2014,939825713,8/19/2014,4168,109.28,35.84,455479.04,149381.12,306097.92 +Asia,Bangladesh,Clothes,Online,L,1/13/2017,187310731,3/1/2017,8263,109.28,35.84,902980.64,296145.92,606834.72 +Central America and the Caribbean,Honduras,Household,Offline,H,2/8/2017,522840487,2/13/2017,8974,668.27,502.54,5997054.98,4509793.96,1487261.02 +Asia,Mongolia,Personal Care,Offline,C,2/19/2014,832401311,2/23/2014,4901,81.73,56.67,400558.73,277739.67,122819.06 +Europe,Bulgaria,Clothes,Online,M,4/23/2012,972292029,6/3/2012,1673,109.28,35.84,182825.44,59960.32,122865.12 +Asia,Sri Lanka,Cosmetics,Offline,M,11/19/2016,419123971,12/18/2016,6952,437.20,263.33,3039414.40,1830670.16,1208744.24 +Sub-Saharan Africa,Cameroon,Beverages,Offline,C,4/1/2015,519820964,4/18/2015,5430,47.45,31.79,257653.50,172619.70,85033.80 +Asia,Turkmenistan,Household,Offline,L,12/30/2010,441619336,1/20/2011,3830,668.27,502.54,2559474.10,1924728.20,634745.90 +Australia and Oceania,East Timor,Meat,Online,L,7/31/2012,322067916,9/11/2012,5908,421.89,364.69,2492526.12,2154588.52,337937.60 +Europe,Norway,Baby Food,Online,L,5/14/2014,819028031,6/28/2014,7450,255.28,159.42,1901836.00,1187679.00,714157.00 +Europe,Portugal,Baby Food,Online,H,7/31/2015,860673511,9/3/2015,1273,255.28,159.42,324971.44,202941.66,122029.78 +Central America and the Caribbean,Honduras,Snacks,Online,L,6/30/2016,795490682,7/26/2016,2225,152.58,97.44,339490.50,216804.00,122686.50 +Australia and Oceania,New Zealand,Fruits,Online,H,9/8/2014,142278373,10/4/2014,2187,9.33,6.92,20404.71,15134.04,5270.67 +Europe,Moldova ,Personal Care,Online,L,5/7/2016,740147912,5/10/2016,5070,81.73,56.67,414371.10,287316.90,127054.20 +Europe,France,Cosmetics,Online,H,5/22/2017,898523128,6/5/2017,1815,437.20,263.33,793518.00,477943.95,315574.05 +Australia and Oceania,Kiribati,Fruits,Online,M,10/13/2014,347140347,11/10/2014,5398,9.33,6.92,50363.34,37354.16,13009.18 +Sub-Saharan Africa,Mali,Fruits,Online,L,5/7/2010,686048400,5/10/2010,5822,9.33,6.92,54319.26,40288.24,14031.02 +Europe,Norway,Beverages,Offline,C,7/18/2014,435608613,7/30/2014,5124,47.45,31.79,243133.80,162891.96,80241.84 +Sub-Saharan Africa,The Gambia,Household,Offline,L,5/26/2012,886494815,6/9/2012,2370,668.27,502.54,1583799.90,1191019.80,392780.10 +Europe,Switzerland,Cosmetics,Offline,M,9/17/2012,249693334,10/20/2012,8661,437.20,263.33,3786589.20,2280701.13,1505888.07 +Sub-Saharan Africa,South Sudan,Personal Care,Offline,C,12/29/2013,406502997,1/28/2014,2125,81.73,56.67,173676.25,120423.75,53252.50 +Australia and Oceania,Australia,Office Supplies,Online,C,10/27/2015,158535134,11/25/2015,2924,651.21,524.96,1904138.04,1534983.04,369155.00 +Asia,Myanmar,Household,Offline,H,1/16/2015,177713572,3/1/2015,8250,668.27,502.54,5513227.50,4145955.00,1367272.50 +Sub-Saharan Africa,Djibouti,Snacks,Online,M,2/25/2017,756274640,2/25/2017,7327,152.58,97.44,1117953.66,713942.88,404010.78 +Central America and the Caribbean,Costa Rica,Personal Care,Offline,L,5/8/2017,456767165,5/21/2017,6409,81.73,56.67,523807.57,363198.03,160609.54 +Middle East and North Africa,Syria,Fruits,Online,L,11/22/2011,162052476,12/3/2011,3784,9.33,6.92,35304.72,26185.28,9119.44 +Sub-Saharan Africa,The Gambia,Meat,Online,M,1/14/2017,825304400,1/23/2017,4767,421.89,364.69,2011149.63,1738477.23,272672.40 +Asia,Brunei,Office Supplies,Online,L,4/1/2012,320009267,5/8/2012,6708,651.21,524.96,4368316.68,3521431.68,846885.00 +Europe,Bulgaria,Office Supplies,Online,M,2/16/2012,189965903,2/28/2012,3987,651.21,524.96,2596374.27,2093015.52,503358.75 +Sub-Saharan Africa,Niger,Personal Care,Online,H,3/11/2017,699285638,3/28/2017,3015,81.73,56.67,246415.95,170860.05,75555.90 +Middle East and North Africa,Azerbaijan,Cosmetics,Online,M,2/6/2010,382392299,2/25/2010,7234,437.20,263.33,3162704.80,1904929.22,1257775.58 +Sub-Saharan Africa,The Gambia,Cereal,Offline,H,6/7/2012,994022214,6/8/2012,2117,205.70,117.11,435466.90,247921.87,187545.03 +Europe,Slovakia,Vegetables,Online,H,10/6/2012,759224212,11/10/2012,171,154.06,90.93,26344.26,15549.03,10795.23 +Asia,Myanmar,Clothes,Online,H,11/14/2015,223359620,11/18/2015,5930,109.28,35.84,648030.40,212531.20,435499.20 +Sub-Saharan Africa,Comoros,Cereal,Offline,H,3/29/2016,902102267,4/29/2016,962,205.70,117.11,197883.40,112659.82,85223.58 +Europe,Iceland,Cosmetics,Online,C,12/31/2016,331438481,12/31/2016,8867,437.20,263.33,3876652.40,2334947.11,1541705.29 +Europe,Switzerland,Personal Care,Online,M,12/23/2010,617667090,1/31/2011,273,81.73,56.67,22312.29,15470.91,6841.38 +Europe,Macedonia,Clothes,Offline,C,10/14/2014,787399423,11/14/2014,7842,109.28,35.84,856973.76,281057.28,575916.48 +Sub-Saharan Africa,Mauritania,Office Supplies,Offline,C,1/11/2012,837559306,1/13/2012,1266,651.21,524.96,824431.86,664599.36,159832.50 +Europe,Albania,Clothes,Online,C,2/2/2010,385383069,3/18/2010,2269,109.28,35.84,247956.32,81320.96,166635.36 +Sub-Saharan Africa,Lesotho,Fruits,Online,L,8/18/2013,918419539,9/18/2013,9606,9.33,6.92,89623.98,66473.52,23150.46 +Middle East and North Africa,Saudi Arabia,Cereal,Online,M,3/25/2013,844530045,3/28/2013,4063,205.70,117.11,835759.10,475817.93,359941.17 +Sub-Saharan Africa,Sierra Leone,Office Supplies,Offline,M,11/26/2011,441888415,1/7/2012,3457,651.21,524.96,2251232.97,1814786.72,436446.25 +Sub-Saharan Africa,Sao Tome and Principe,Fruits,Offline,H,9/17/2013,508980977,10/24/2013,7637,9.33,6.92,71253.21,52848.04,18405.17 +Sub-Saharan Africa,Cote d'Ivoire,Clothes,Online,C,6/8/2012,114606559,6/27/2012,3482,109.28,35.84,380512.96,124794.88,255718.08 +Australia and Oceania,Fiji,Clothes,Offline,C,6/30/2010,647876489,8/1/2010,9905,109.28,35.84,1082418.40,354995.20,727423.20 +Europe,Austria,Cosmetics,Offline,H,2/23/2015,868214595,3/2/2015,2847,437.20,263.33,1244708.40,749700.51,495007.89 +Europe,United Kingdom,Household,Online,L,1/5/2012,955357205,2/14/2012,282,668.27,502.54,188452.14,141716.28,46735.86 +Sub-Saharan Africa,Djibouti,Cosmetics,Offline,H,4/7/2014,259353148,4/19/2014,7215,437.20,263.33,3154398.00,1899925.95,1254472.05 +Australia and Oceania,Australia,Cereal,Offline,H,6/9/2013,450563752,7/2/2013,682,205.70,117.11,140287.40,79869.02,60418.38 +Europe,San Marino,Baby Food,Online,L,6/26/2013,569662845,7/1/2013,4750,255.28,159.42,1212580.00,757245.00,455335.00 +Sub-Saharan Africa,Cameroon,Office Supplies,Online,M,11/7/2011,177636754,11/15/2011,5518,651.21,524.96,3593376.78,2896729.28,696647.50 +Middle East and North Africa,Libya,Clothes,Offline,H,10/30/2010,705784308,11/17/2010,6116,109.28,35.84,668356.48,219197.44,449159.04 +Central America and the Caribbean,Haiti,Cosmetics,Offline,H,10/13/2013,505716836,11/16/2013,1705,437.20,263.33,745426.00,448977.65,296448.35 +Sub-Saharan Africa,Rwanda,Cosmetics,Offline,H,10/11/2013,699358165,11/25/2013,4477,437.20,263.33,1957344.40,1178928.41,778415.99 +Sub-Saharan Africa,Gabon,Personal Care,Offline,L,7/8/2012,228944623,7/9/2012,8656,81.73,56.67,707454.88,490535.52,216919.36 +Central America and the Caribbean,Belize,Clothes,Offline,M,7/25/2016,807025039,9/7/2016,5498,109.28,35.84,600821.44,197048.32,403773.12 +Europe,Lithuania,Office Supplies,Offline,H,10/24/2010,166460740,11/17/2010,8287,651.21,524.96,5396577.27,4350343.52,1046233.75 +Sub-Saharan Africa,Madagascar,Clothes,Offline,L,4/25/2015,610425555,5/28/2015,7342,109.28,35.84,802333.76,263137.28,539196.48 +Asia,Turkmenistan,Office Supplies,Online,M,4/23/2013,462405812,5/20/2013,5010,651.21,524.96,3262562.10,2630049.60,632512.50 +Middle East and North Africa,Libya,Fruits,Online,L,8/14/2015,816200339,9/30/2015,673,9.33,6.92,6279.09,4657.16,1621.93 +Sub-Saharan Africa,Democratic Republic of the Congo,Beverages,Online,C,5/26/2011,585920464,7/15/2011,5741,47.45,31.79,272410.45,182506.39,89904.06 +Sub-Saharan Africa,Djibouti,Cereal,Online,H,5/20/2017,555990016,6/17/2017,8656,205.70,117.11,1780539.20,1013704.16,766835.04 +Middle East and North Africa,Pakistan,Cosmetics,Offline,L,7/5/2013,231145322,8/16/2013,9892,437.20,263.33,4324782.40,2604860.36,1719922.04 +North America,Mexico,Household,Offline,C,11/6/2014,986435210,12/12/2014,6954,668.27,502.54,4647149.58,3494663.16,1152486.42 +Australia and Oceania,Federated States of Micronesia,Beverages,Online,C,10/28/2014,217221009,11/15/2014,9379,47.45,31.79,445033.55,298158.41,146875.14 +Asia,Laos,Vegetables,Offline,C,9/15/2011,789176547,10/23/2011,3732,154.06,90.93,574951.92,339350.76,235601.16 +Europe,Monaco,Baby Food,Offline,H,5/29/2012,688288152,6/2/2012,8614,255.28,159.42,2198981.92,1373243.88,825738.04 +Australia and Oceania,Samoa ,Cosmetics,Online,H,7/20/2013,670854651,8/7/2013,9654,437.20,263.33,4220728.80,2542187.82,1678540.98 +Europe,Spain,Household,Offline,L,10/21/2012,213487374,11/30/2012,4513,668.27,502.54,3015902.51,2267963.02,747939.49 +Middle East and North Africa,Lebanon,Clothes,Online,L,9/18/2012,663110148,10/8/2012,7884,109.28,35.84,861563.52,282562.56,579000.96 +Middle East and North Africa,Iran,Cosmetics,Online,H,11/15/2016,286959302,12/8/2016,6489,437.20,263.33,2836990.80,1708748.37,1128242.43 +Sub-Saharan Africa,Zambia,Snacks,Online,L,1/4/2011,122583663,1/5/2011,4085,152.58,97.44,623289.30,398042.40,225246.90 +Sub-Saharan Africa,Kenya,Vegetables,Online,L,3/18/2012,827844560,4/7/2012,6457,154.06,90.93,994765.42,587135.01,407630.41 +North America,Mexico,Personal Care,Offline,L,2/17/2012,430915820,3/20/2012,6422,81.73,56.67,524870.06,363934.74,160935.32 +Sub-Saharan Africa,Sao Tome and Principe,Beverages,Offline,C,1/16/2011,180283772,1/21/2011,8829,47.45,31.79,418936.05,280673.91,138262.14 +Sub-Saharan Africa,The Gambia,Baby Food,Offline,M,2/3/2014,494747245,3/20/2014,5559,255.28,159.42,1419101.52,886215.78,532885.74 +Middle East and North Africa,Kuwait,Fruits,Online,M,4/30/2012,513417565,5/18/2012,522,9.33,6.92,4870.26,3612.24,1258.02 +Europe,Slovenia,Beverages,Offline,C,10/23/2016,345718562,11/25/2016,4660,47.45,31.79,221117.00,148141.40,72975.60 +Sub-Saharan Africa,Sierra Leone,Office Supplies,Offline,H,12/6/2016,621386563,12/14/2016,948,651.21,524.96,617347.08,497662.08,119685.00 +Australia and Oceania,Australia,Beverages,Offline,H,7/7/2014,240470397,7/11/2014,9389,47.45,31.79,445508.05,298476.31,147031.74 +Middle East and North Africa,Azerbaijan,Office Supplies,Online,M,6/13/2012,423331391,7/24/2012,2021,651.21,524.96,1316095.41,1060944.16,255151.25 +Europe,Romania,Cosmetics,Online,H,11/26/2010,660643374,12/25/2010,7910,437.20,263.33,3458252.00,2082940.30,1375311.70 +Central America and the Caribbean,Nicaragua,Beverages,Offline,C,2/8/2011,963392674,3/21/2011,8156,47.45,31.79,387002.20,259279.24,127722.96 +Sub-Saharan Africa,Mali,Clothes,Online,M,7/26/2011,512878119,9/3/2011,888,109.28,35.84,97040.64,31825.92,65214.72 +Asia,Malaysia,Fruits,Offline,L,11/11/2011,810711038,12/28/2011,6267,9.33,6.92,58471.11,43367.64,15103.47 +Sub-Saharan Africa,Sierra Leone,Vegetables,Offline,C,6/1/2016,728815257,6/29/2016,1485,154.06,90.93,228779.10,135031.05,93748.05 +North America,Mexico,Personal Care,Offline,M,7/30/2015,559427106,8/8/2015,5767,81.73,56.67,471336.91,326815.89,144521.02 +Sub-Saharan Africa,Mozambique,Household,Offline,L,2/10/2012,665095412,2/15/2012,5367,668.27,502.54,3586605.09,2697132.18,889472.91 diff --git a/main3.py b/main3.py new file mode 100644 index 0000000..1f7c89d --- /dev/null +++ b/main3.py @@ -0,0 +1,57 @@ +#### INCLUDE ANY IMPORTS YOU NEED HERE, DO NOT PIP INSTALL ANY LIBRARIES #### + + +def perfect_square(num): + '''Return the sqrt of only if is a perfect square, otherwise return -1.''' + # Hint: math library + return 0 + + +def random_num_generator(min, max): + '''Returns a random number between min and max inclusive.''' + # Hint: random library + return 0 + + +def get_today(): + '''Returns today's date in the format , where month is a string, day & year are numbers.''' + # Note: Code must work regardless of today's date + # Example: November 19, 2021 + # Hint: datetime library + return "November 19, 2021" + + +def get_stat(nums, type): + '''Returns of an unsorted list , where type can be mean, median, mode.''' + # Example: get_stat([0, 1, 2], "median"), returns 1 + # Hint: statistics library + return 0 + + +def print_by_profit(): + '''Print data/sales_records.csv in order sorted by profit.''' + # Hint: csv library + # Hint: use built-in sort() after parsing csv + # Hint: figure out how to print out each row in csv first + print("Working with csvs!") + + +def main(): + '''Challenge 3 focuses on using some of Python's built-in functions and libraries.''' + # Testing challenge 3 + print("\nTesting perfect_square") + print("EXPECTED:", -1, "\nACTUAL:", perfect_square(24)) + print("EXPECTED:", 5, "\nACTUAL:", perfect_square(25)) + print("\nTesting random_num_generator") + print("EXPECTED:", "[1, 10]", "\nACTUAL:", random_num_generator(1, 10)) + print("\nTesting get_today") + print("EXPECTED:", "October 26, 2021", "\nACTUAL:", get_today()) + print("\nTesting get_stat") + print("EXPECTED:", 1, "\nACTUAL:", get_stat([0, 1, 2], "median")) + print("\nTesting print_by_profit") + print_by_profit() + # Add any additional test cases if needed + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/solution.py b/solution.py old mode 100644 new mode 100755 diff --git a/solution2.py b/solution2.py new file mode 100755 index 0000000..0f1da1e --- /dev/null +++ b/solution2.py @@ -0,0 +1,61 @@ +def oddOrEven(nums): + '''Given an unsorted list of numbers, return a list that indicates if the value at each index is odd (0) or even (1).''' + # EXAMPLE: + # Given [2, 4, 5, 7, 8, 10], return [1, 1, 0, 0, 1, 1] + + solution = [] + + # Push into solution as we determine if num is even or odd + for num in nums: + if num % 2 == 0: + solution.append(1) + else: + solution.append(0) + + # Likewise, can also just replace the indexes of nums + # for i, num in enumerate(nums): + # if num % 2 == 0: + # nums[i] = 1 + # else: + # nums[i] = 0 + + return solution # return nums if use second solution + + +def mostOccurences(nums): + '''Given an unsorted list of numbers, returns the value that occured the most in nums.''' + # Hint: use oddOrEven to test function faster + # Hint: use a map + # Hint: https://stackoverflow.com/questions/13098638/how-to-iterate-over-the-elements-of-a-map-in-python + + uniqueCount = {} + + for num in nums: + # Check if key already exists, if so, just add one to count + if num in uniqueCount: + uniqueCount[num] += 1 + # Key doesn't exist, set count to 1 + else: + uniqueCount[num] = 1 + + answer = -1 # answer to keep track of the key + maxCount = 0 # maxCount to keep track of max count we've seen in uniqueCount + for key in uniqueCount: + if uniqueCount[key] > maxCount: + answer = key # update answer + maxCount = uniqueCount[key] # update maxCount + + return answer + + +def main(): + '''The main function is where you will test all of your functions.''' + # Testing challenge 2 + print("\nTesting oddOrEven") + print("EXPECTED:", [1, 1, 0, 0, 1, 1], "\nACTUAL:", oddOrEven([2, 4, 5, 7, 8, 10])) + print("\nTesting mostOccurences") + print("EXPECTED:", 1, "\nACTUAL:", mostOccurences(oddOrEven([2, 4, 5, 7, 8, 10]))) + # Add any additional test cases if needed + +if __name__ == "__main__": + main() \ No newline at end of file