From e77e609b8ba57605269d37e4298855523cc2ad93 Mon Sep 17 00:00:00 2001 From: mamalesh <98878729+mamalesh@users.noreply.github.com> Date: Sun, 6 Feb 2022 22:25:39 +0530 Subject: [PATCH 1/2] Update README.md --- README.md | 298 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 297 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3dd2521..eb1f2a3 100644 --- a/README.md +++ b/README.md @@ -1 +1,297 @@ -# Python-Workshop \ No newline at end of file +# Python-Workshop +# ## Exercises + +# Answer the questions or complete the tasks outlined in bold below. + + +def power(a,b): + + + # ** What is 7 to the power of 4?** + + + return a**b + + + + +def split_str(s): + + # ** Split this string:** + +# +# s = "Hi there Sam!" +# +# **into a list. ** + + return s.split() + + + +def format(planet,diameter): + print('The diameter of {} is {} kilometers.'.format(planet,diameter)) + +# ** Given the variables:** +# +# planet = "Earth" +# diameter = 12742 +# +# ** Use .format() to print the following string: ** +# +# The diameter of Earth is 12742 kilometers. + + 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 lst[3][1][2][0] +#indexing(lst) + + +def dictionary(d): + +# ** Given this nested dictionary grab the word "hello". Be prepared, this will be annoying/tricky ** + + + + return d['k1'][3]['tricky'][3]['target'][3] + + + +def subjective(): + +# ** What is the main difference between a tuple and a list? ** +# Tuple is ___immutable____ + + return immutable + + + + +def domainGet(email): + + + # ** Create a function that grabs the email website domain from a string in the form: ** +# +# user@domain.com +# +# **So for example, passing "user@domain.com" would return: domain.com** + + return email.split('@')[1] + + + +def findDog(st): + st=st.lower() + if (st.find('dog')==-1): + val ='False' + else: + val='True' + + + +# ** 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 val + + + +def countDog(st): + st=st.lower() + + + +# ** Create a function that counts the number of times the word "dog" occurs in a string. Again ignore edge cases. ** + + return st.count('dog') + + + + +def lambdafunc(seq): + + + # ** Use lambda expressions and the filter() function to filter out words from a list that don't start with the letter 's'. For example:** +# +# +# **should be filtered down to:** +# +# ['soup','salad'] + + return list(filter( lambda item:item[0]=='s',seq)) + + + + +def caught_speeding(speed, is_birthday): + if(is_birthday==True): + speed=speed-5 + + if(speed<=60): + valu="No ticket" + elif(speed<=80): + valu="Small ticket" + else: + valu="Big Ticket" + + + +# **You are driving a little too fast, and a police officer stops you. Write a function +# to return one of 3 possible results: "No ticket", "Small ticket", or "Big Ticket". +# If your speed is 60 or less, the result is "No Ticket". If speed is between 61 +# 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 valu + + + +## Numpy Exercises + +import numpy as np + + +def create_arr_of_fives(): + arr=np.ones(5); + arr=arr*5; + + + #### Create an array of 10 fives + + #### Convert your output into list + #### e.g return list(arr) + + return list(arr) + + + + +def even_num(): + arr=np.linspace(0,50,26) + + ### Create an array of all the even integers from 10 to 50 + ### Convert your output into list + ### e.g return list(arr) + + return list(arr) + + + +def create_matrix(): + arr=np.arange(9) + arr=list(arr.reshape(3,3)) + + ### Create a 3x3 matrix with values ranging from 0 to 8 + ### Convert your output into list + ### e.g return (arr).tolist() + + return arr + + + + + + +def linear_space(): + l=np.linspace(0,1,20) + ### Create an array of 20 linearly spaced points between 0 and 1 + ### Convert your output into list + ### e.g return list(arr) + + return list(l) + + + +def decimal_mat(): + li=np.linspace(1,100,100).reshape(10,10) + li=li/100 + + + ### Create an array of size 10*10 consisting of numbers from 0.01 to 1 + ### Convert your output into list + ### e.g return (arr).tolist() + + return list(li) + + + +def slices_1(): + + # This is a given array + arr = np.arange(1,26).reshape(5,5) + # array([[ 1, 2, 3, 4, 5], + # [ 6, 7, 8, 9, 10], + # [11, 12, 13, 14, 15], + # [16, 17, 18, 19, 20], + # [21, 22, 23, 24, 25]]) + arr=arr[2:,1:] + + # Write a code to slice this given array + ### Convert your output into list + ### e.g return (arr).tolist() + # array([[12, 13, 14, 15], + # [17, 18, 19, 20], + # [22, 23, 24, 25]]) + + return list(arr) + + + +def slices_2(): + + # This is a given array + arr = np.arange(1,26).reshape(5,5) + + # array([[ 1, 2, 3, 4, 5], + # [ 6, 7, 8, 9, 10], + # [11, 12, 13, 14, 15], + # [16, 17, 18, 19, 20], + # [21, 22, 23, 24, 25]]) + arr=arr[:3,1] + + + # Write a code to slice this given array + ### Convert your output into list + ### e.g return (arr).tolist() + # array([[ 2], + # [ 7], + # [12]]) + + return list(arr) + + + + +def slices_3(): + + # This is a given array + arr = np.arange(1,26).reshape(5,5) + + # array([[ 1, 2, 3, 4, 5], + # [ 6, 7, 8, 9, 10], + # [11, 12, 13, 14, 15], + # [16, 17, 18, 19, 20], + # [21, 22, 23, 24, 25]]) + arr=arr[3:,:] + + + # Write a code to slice this given array + ### Convert your output into list + ### e.g return (arr).tolist() + # array([[16, 17, 18, 19, 20], + # [21, 22, 23, 24, 25]]) + + return list(arr) + + + +# Great job! From dd4f4f6f78b7157d0bcb08306ebf62c7b192331c Mon Sep 17 00:00:00 2001 From: mamalesh <98878729+mamalesh@users.noreply.github.com> Date: Mon, 7 Feb 2022 00:00:21 +0530 Subject: [PATCH 2/2] Update README.md --- README.md | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index eb1f2a3..d116309 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ # Answer the questions or complete the tasks outlined in bold below. -def power(a,b): + def power(a,b): # ** What is 7 to the power of 4?** @@ -15,7 +15,7 @@ def power(a,b): -def split_str(s): + def split_str(s): # ** Split this string:** @@ -28,7 +28,7 @@ def split_str(s): -def format(planet,diameter): + def format(planet,diameter): print('The diameter of {} is {} kilometers.'.format(planet,diameter)) # ** Given the variables:** @@ -45,8 +45,7 @@ def format(planet,diameter): - -def indexing(lst): + def indexing(lst): # ** Given this nested list, use indexing to grab the word "hello" ** @@ -67,7 +66,7 @@ def dictionary(d): -def subjective(): + def subjective(): # ** What is the main difference between a tuple and a list? ** # Tuple is ___immutable____ @@ -77,7 +76,7 @@ def subjective(): -def domainGet(email): + def domainGet(email): # ** Create a function that grabs the email website domain from a string in the form: ** @@ -90,7 +89,7 @@ def domainGet(email): -def findDog(st): + def findDog(st): st=st.lower() if (st.find('dog')==-1): val ='False' @@ -105,7 +104,7 @@ def findDog(st): -def countDog(st): + def countDog(st): st=st.lower() @@ -117,7 +116,7 @@ def countDog(st): -def lambdafunc(seq): + def lambdafunc(seq): # ** Use lambda expressions and the filter() function to filter out words from a list that don't start with the letter 's'. For example:** @@ -132,7 +131,7 @@ def lambdafunc(seq): -def caught_speeding(speed, is_birthday): + def caught_speeding(speed, is_birthday): if(is_birthday==True): speed=speed-5 @@ -160,7 +159,7 @@ def caught_speeding(speed, is_birthday): import numpy as np -def create_arr_of_fives(): + def create_arr_of_fives(): arr=np.ones(5); arr=arr*5; @@ -175,7 +174,7 @@ def create_arr_of_fives(): -def even_num(): + def even_num(): arr=np.linspace(0,50,26) ### Create an array of all the even integers from 10 to 50 @@ -186,7 +185,7 @@ def even_num(): -def create_matrix(): + def create_matrix(): arr=np.arange(9) arr=list(arr.reshape(3,3)) @@ -201,7 +200,7 @@ def create_matrix(): -def linear_space(): + def linear_space(): l=np.linspace(0,1,20) ### Create an array of 20 linearly spaced points between 0 and 1 ### Convert your output into list @@ -209,9 +208,7 @@ def linear_space(): return list(l) - - -def decimal_mat(): + def decimal_mat(): li=np.linspace(1,100,100).reshape(10,10) li=li/100 @@ -224,7 +221,7 @@ def decimal_mat(): -def slices_1(): + def slices_1(): # This is a given array arr = np.arange(1,26).reshape(5,5) @@ -246,7 +243,7 @@ def slices_1(): -def slices_2(): + def slices_2(): # This is a given array arr = np.arange(1,26).reshape(5,5) @@ -271,7 +268,7 @@ def slices_2(): -def slices_3(): + def slices_3(): # This is a given array arr = np.arange(1,26).reshape(5,5)