From 532f93dec9cc9fab05fcc69f754cfb220fda47f4 Mon Sep 17 00:00:00 2001 From: Siddanth Shetty Date: Mon, 7 Feb 2022 11:27:11 +0530 Subject: [PATCH 1/5] new changes --- Python_Exercises.py | 99 +++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 43 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index d7e6135..4faaea9 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -7,65 +7,59 @@ def power(a,b): # ** What is 7 to the power of 4?** + ans=a**b - return None + return ans def split_str(s): # ** Split this string:** -# -# s = "Hi there Sam!" -# + s = "Hi there Sam!" + my_list=list(s.split()) # **into a list. ** + print (my_list) - return None + return list def format(planet,diameter): # ** Given the variables:** # -# planet = "Earth" -# diameter = 12742 -# -# ** Use .format() to print the following string: ** -# -# The diameter of Earth is 12742 kilometers. + planet = "Earth" + diameter = 12742 - return None +# ** Use .format() to print the following string: ** + print("The diameter of: {} is: {} kilometers".format(planet,diameter)) + return None def indexing(lst): # ** Given this nested list, use indexing to grab the word "hello" ** -#lst = [1,2,[3,4],[5,[100,200,['hello']],23,11],1,7] - - return None + lst = [1,2,[3,4],[5,[100,200,['hello']],23,11],1,7] + + return lst[3][1][2][0] def dictionary(d): # ** Given this nested dictionary grab the word "hello". Be prepared, this will be annoying/tricky ** -# d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':[1,2,3,'hello']}]}]} - - - return None + d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':[1,2,3,'hello']}]}]} + return d['k1'][3]['tricky'][3]['target'][3] def subjective(): # ** What is the main difference between a tuple and a list? ** -# Tuple is _______ - - return None - - +#Tuple is _______ + return "immutable" def domainGet(email): @@ -74,23 +68,21 @@ def domainGet(email): # user@domain.com # # **So for example, passing "user@domain.com" would return: domain.com** - - return None + my_list=list(email.split("@")) + return str(my_list[1]) def findDog(st): # ** Create a basic function that returns True if the word 'dog' is contained in the input string. Don't worry about edge cases like a punctuation being attached to the word dog, but do account for capitalization. ** - return None - + return "dog" in st.lower() def countDog(st): # ** Create a function that counts the number of times the word "dog" occurs in a string. Again ignore edge cases. ** - - return None - + + return len(st.lower().split("dog"))-1 def lambdafunc(seq): @@ -103,7 +95,7 @@ def lambdafunc(seq): # # ['soup','salad'] - return None + return list(filter(lambda var:var[0]=='s',(seq))) def caught_speeding(speed, is_birthday): @@ -115,7 +107,24 @@ def caught_speeding(speed, is_birthday): # and 80 inclusive, the result is "Small Ticket". If speed is 81 or more, the result is "Big Ticket". Unless it is your birthday (encoded as a boolean value in the parameters of the function) -- on your birthday, your speed can be 5 higher in all # cases. ** - return None + if (is_birthday): + if (speed<=65) : + return "No ticket" + elif (speed>65 & speed<=85) : + return "Small ticket" + else: + return "Big ticket" + + else: + if (speed<=60) : + return "No ticket" + elif (speed>60 & speed<=80) : + return "Small ticket" + else: + return "Big ticket" + + + ## Numpy Exercises @@ -128,9 +137,8 @@ def create_arr_of_fives(): #### Create an array of 10 fives #### Convert your output into list #### e.g return list(arr) - - return None - + arr=np.full(10,5) + return list(arr) def even_num(): @@ -139,7 +147,9 @@ def even_num(): ### Convert your output into list ### e.g return list(arr) - return None + arr=np.arange(10,51,2) + + return list(arr) @@ -149,7 +159,9 @@ def create_matrix(): ### Convert your output into list ### e.g return (arr).tolist() - return None + my_list=np.arange(9).reshape(3,3).tolist() + + return my_list @@ -159,7 +171,7 @@ def linear_space(): ### Convert your output into list ### e.g return list(arr) - return None + return list(np.linspace(0,1,20)) @@ -169,7 +181,7 @@ def decimal_mat(): ### Convert your output into list ### e.g return (arr).tolist() - return None + return (np.linspace(0.01,1,100).reshape(10,10).tolist()) @@ -190,7 +202,8 @@ def slices_1(): # [17, 18, 19, 20], # [22, 23, 24, 25]]) - return None + return arr[2: ,1: ].tolist() + @@ -211,7 +224,7 @@ def slices_2(): # [ 7], # [12]]) - return None + return (arr[ :3,1:2].tolist()) @@ -231,7 +244,7 @@ def slices_3(): # array([[16, 17, 18, 19, 20], # [21, 22, 23, 24, 25]]) - return None + return arr[3: , ].tolist() # Great job! From eff02e39bca84532629ee4e0da820a2006a6da97 Mon Sep 17 00:00:00 2001 From: Siddanth Shetty Date: Mon, 7 Feb 2022 11:50:20 +0530 Subject: [PATCH 2/5] updates --- Python_Exercises.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index 4faaea9..d418552 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -32,7 +32,7 @@ def format(planet,diameter): diameter = 12742 # ** Use .format() to print the following string: ** - print("The diameter of: {} is: {} kilometers".format(planet,diameter)) + print("The diameter of: {} is: {} kilometers.".format(planet,diameter)) return None @@ -107,24 +107,19 @@ def caught_speeding(speed, is_birthday): # and 80 inclusive, the result is "Small Ticket". If speed is 81 or more, the result is "Big Ticket". Unless it is your birthday (encoded as a boolean value in the parameters of the function) -- on your birthday, your speed can be 5 higher in all # cases. ** + if (is_birthday): - if (speed<=65) : - return "No ticket" - elif (speed>65 & speed<=85) : - return "Small ticket" - else: - return "Big ticket" - + limits =[65,85] else: - if (speed<=60) : - return "No ticket" - elif (speed>60 & speed<=80) : - return "Small ticket" - else: - return "Big ticket" - + limits =[60,80] - + if speed<=limits[0]: + return "No ticket" + elif speed<=limits[1]: + return "Small ticket" + else: + return "Big ticket" + ## Numpy Exercises @@ -181,7 +176,7 @@ def decimal_mat(): ### Convert your output into list ### e.g return (arr).tolist() - return (np.linspace(0.01,1,100).reshape(10,10).tolist()) + return np.around(np.linspace(0.01,1.,100),decimals=2).reshape(10,10).tolist() From 7342285347a7764adfb6f097107096167db0cfb4 Mon Sep 17 00:00:00 2001 From: Siddanth Shetty Date: Mon, 7 Feb 2022 11:55:49 +0530 Subject: [PATCH 3/5] update2 --- Python_Exercises.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index d418552..a822887 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -32,7 +32,7 @@ def format(planet,diameter): diameter = 12742 # ** Use .format() to print the following string: ** - print("The diameter of: {} is: {} kilometers.".format(planet,diameter)) + print("The diameter of {} is {} kilometers.".format(planet,diameter)) return None @@ -114,11 +114,11 @@ def caught_speeding(speed, is_birthday): limits =[60,80] if speed<=limits[0]: - return "No ticket" + return "No Ticket" elif speed<=limits[1]: - return "Small ticket" + return "Small Ticket" else: - return "Big ticket" + return "Big Ticket" From 4077bc43af9d910de59a09cd6c59c78979163297 Mon Sep 17 00:00:00 2001 From: Siddanth Shetty Date: Mon, 7 Feb 2022 12:01:06 +0530 Subject: [PATCH 4/5] update3 --- Python_Exercises.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index a822887..0df464e 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -32,9 +32,9 @@ def format(planet,diameter): diameter = 12742 # ** Use .format() to print the following string: ** - print("The diameter of {} is {} kilometers.".format(planet,diameter)) + - return None + return "The diameter of {} is {} kilometers.".format(planet,diameter) def indexing(lst): From cfc865e89b8994715354cfb098de08f7e4484b87 Mon Sep 17 00:00:00 2001 From: Siddanth Shetty Date: Mon, 7 Feb 2022 12:23:45 +0530 Subject: [PATCH 5/5] update4 --- Python_Exercises.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Python_Exercises.py b/Python_Exercises.py index 0df464e..8058840 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -19,9 +19,9 @@ def split_str(s): s = "Hi there Sam!" my_list=list(s.split()) # **into a list. ** - print (my_list) + - return list + return my_list def format(planet,diameter): @@ -154,9 +154,9 @@ def create_matrix(): ### Convert your output into list ### e.g return (arr).tolist() - my_list=np.arange(9).reshape(3,3).tolist() + - return my_list + return np.arange(9).reshape(3,3).tolist()