diff --git a/Python_Exercises.py b/Python_Exercises.py index d7e6135..df39bf7 100644 --- a/Python_Exercises.py +++ b/Python_Exercises.py @@ -7,8 +7,10 @@ def power(a,b): # ** What is 7 to the power of 4?** - - return None + a=7 + b=4 + z=a**b + return None @@ -20,6 +22,7 @@ def split_str(s): # # **into a list. ** + return None @@ -33,7 +36,9 @@ def format(planet,diameter): # ** Use .format() to print the following string: ** # # The diameter of Earth is 12742 kilometers. - +planet="Earth" +diameter=12742 +print('The diameter of :{two},is :{one}'.format{one=diameter,two=planet}) return None @@ -43,6 +48,9 @@ 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] +lst = [1,2,[3,4],[5,[100,200,['hello']],23,11],1,7] +d = lst[3][1][2][0] +print(d) return None @@ -52,7 +60,9 @@ 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']}]}]} - +d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':[1,2,3,'hello']}]}]} +z = d['k1'][3]['tricky'][3]['target'][3] +print(z) return None @@ -60,7 +70,8 @@ def dictionary(d): def subjective(): # ** What is the main difference between a tuple and a list? ** -# Tuple is _______ +# Tuple is _______ +List can be changed while Tupple cannot be changed means we can append list but cannot do the same with tuple. return None @@ -74,6 +85,10 @@ def domainGet(email): # user@domain.com # # **So for example, passing "user@domain.com" would return: domain.com** +z='amey@domain.com' +x=z.split("@")[-1] +print(x) + return None @@ -81,14 +96,19 @@ def domainGet(email): 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. ** - +k="each and every person on this planet loves dogs" +x=k.find("dogs") +print(x) +#this function specifies the number on which dog will appear for eg e of each is 0 and a of each is 1 return None def countDog(st): # ** Create a function that counts the number of times the word "dog" occurs in a string. Again ignore edge cases. ** - +y=['dogs','cats','lion','dogs'] +o = y.count("dogs") +print(o) return None @@ -114,6 +134,16 @@ def caught_speeding(speed, is_birthday): # 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. ** +speed = 79 + +if speed<60: +print("NO TICKET") + +elif speed<80: +print("SMALL TICKET") + +else: +print("BIG TICKET") return None @@ -128,6 +158,10 @@ def create_arr_of_fives(): #### Create an array of 10 fives #### Convert your output into list #### e.g return list(arr) +import numpy as np +array=np.ones(10)*5 +print("Array of 10 fives:") +print(array) return None @@ -138,6 +172,10 @@ def even_num(): ### Create an array of all the even integers from 10 to 50 ### Convert your output into list ### e.g return list(arr) +import numpy as np +i=np.arange(10,51,2) +print("Array of all the even integers from 10 to 50") +print(i) return None @@ -148,6 +186,9 @@ def create_matrix(): ### Create a 3x3 matrix with values ranging from 0 to 8 ### Convert your output into list ### e.g return (arr).tolist() +import numpy as np +p = np.arange(0,9).reshape(3,3) +print(p) return None @@ -157,7 +198,10 @@ def linear_space(): ### Create an array of 20 linearly spaced points between 0 and 1 ### Convert your output into list - ### e.g return list(arr) + ### e.g return list(arr) +import numpy as np +c = np.linspace(0,1,20) +print(c) return None @@ -168,6 +212,9 @@ def decimal_mat(): ### 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() +import numpy as np +l = np.linspace(0.01,1,100).reshape(10,10) +print(l) return None @@ -189,7 +236,10 @@ def slices_1(): # array([[12, 13, 14, 15], # [17, 18, 19, 20], # [22, 23, 24, 25]]) - +import numpy as np +array = np.arange(1,26).reshape(5,5) +arr=array.tolist() +print(arr) return None @@ -210,6 +260,10 @@ def slices_2(): # array([[ 2], # [ 7], # [12]]) +import numpy as np +array = np.arange(1,26).reshape(5,5) +arr=array.tolist() +print(arr) return None @@ -230,6 +284,10 @@ def slices_3(): ### e.g return (arr).tolist() # array([[16, 17, 18, 19, 20], # [21, 22, 23, 24, 25]]) +import numpy as np +arr = np.arange(1,26).reshape(5,5) +arr=arr[3:,:] +print(arr) return None