Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 45 additions & 22 deletions Python_Exercises.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def power(a,b):

# ** What is 7 to the power of 4?**

return None
return a**b



Expand All @@ -20,7 +20,7 @@ def split_str(s):
#
# **into a list. **

return None
return s.split(' ')


def format(planet,diameter):
Expand All @@ -34,17 +34,23 @@ def format(planet,diameter):
#
# The diameter of Earth is 12742 kilometers.

return None
return "The diameter of {} is {} kilometers.".format(planet,diameter)





def indexing(lst):

return lst[3][1][2][0]


# ** 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]

return lst[3][1][2][0]


return None


def dictionary(d):
Expand All @@ -54,15 +60,15 @@ def dictionary(d):
# d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':[1,2,3,'hello']}]}]}


return None
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
return "immutable"



Expand All @@ -74,15 +80,16 @@ def domainGet(email):
# user@domain.com
#
# **So for example, passing "user@domain.com" would return: domain.com**
l=email.split('@')

return None
return l[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
r = st.lower()
return "dog" in r


def countDog(st):
Expand All @@ -103,7 +110,7 @@ def lambdafunc(seq):
#
# ['soup','salad']

return None
return list(filter(lambda var:var[0]=='s'or var[0]=='S',seq))


def caught_speeding(speed, is_birthday):
Expand All @@ -114,8 +121,22 @@ 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. **
if is_birthday==True:
if speed<=65:
return "No Ticket"
elif speed >=66 and speed<=85:
return "Small Ticket"
else:
return "Big Ticket"
else:
if speed<=60:
return "No Ticket"
elif speed >=61 and speed<=80:
return "Small Ticket"
else:
return "Big Ticket"

return None



## Numpy Exercises
Expand All @@ -129,7 +150,7 @@ def create_arr_of_fives():
#### Convert your output into list
#### e.g return list(arr)

return None
return (5*np.ones(10)).tolist()



Expand All @@ -139,7 +160,7 @@ def even_num():
### Convert your output into list
### e.g return list(arr)

return None
return np.linspace(10,50,21).tolist()



Expand All @@ -149,8 +170,7 @@ def create_matrix():
### Convert your output into list
### e.g return (arr).tolist()

return None

return np.arange(9).reshape(3,3).tolist()


def linear_space():
Expand All @@ -159,7 +179,7 @@ def linear_space():
### Convert your output into list
### e.g return list(arr)

return None
return np.linspace(0,1,20).tolist()



Expand All @@ -169,7 +189,9 @@ def decimal_mat():
### Convert your output into list
### e.g return (arr).tolist()

return None
return (np.linspace(1,100,100).reshape(10,10)/100).tolist()





Expand All @@ -190,7 +212,7 @@ def slices_1():
# [17, 18, 19, 20],
# [22, 23, 24, 25]])

return None
return (arr[-3:,1:]).tolist()



Expand All @@ -211,7 +233,7 @@ def slices_2():
# [ 7],
# [12]])

return None
return (arr[:3,1:2]).tolist()



Expand All @@ -231,7 +253,8 @@ def slices_3():
# array([[16, 17, 18, 19, 20],
# [21, 22, 23, 24, 25]])

return None
return arr[-2:].tolist()



# Great job!