Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Python_Exercises.py #151

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
68 changes: 67 additions & 1 deletion Python_Exercises.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
def power(a,b):

# ** What is 7 to the power of 4?**
c = a*a*a*a
print('The power of {} to {} is {}' .format(a,b,c))

return None

Expand All @@ -19,6 +21,7 @@ def split_str(s):
# s = "Hi there Sam!"
#
# **into a list. **
s.split()

return None

Expand All @@ -33,6 +36,8 @@ def format(planet,diameter):
# ** Use .format() to print the following string: **
#
# The diameter of Earth is 12742 kilometers.
print('The diameter of {var} is {D} kilometers' .format(var==planet,D==diameter))


return None

Expand All @@ -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]
lst[3][1][2][0]

return None

Expand All @@ -52,6 +60,10 @@ 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']}]}]}

d['k1'][3]['tricky'][3]['target'][3]


return None
Expand All @@ -60,7 +72,7 @@ def dictionary(d):
def subjective():

# ** What is the main difference between a tuple and a list? **
# Tuple is _______
# Tuple is immutable where as list is mutable._______

return None

Expand All @@ -74,20 +86,39 @@ def domainGet(email):
# [email protected]
#
# **So for example, passing "[email protected]" would return: domain.com**





return None


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. **

st = input("Enter the word here.")
if (st=='dog' or st=='DOG'):
print("TRUE")
else:
print("Sorry")

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. **

st = "Dog is a very good animal Dog is dog because Dog is animal"

a=0
b="Dog"
for line in st:
if b in line.split():
a += 1
print(a)

return None

Expand All @@ -102,6 +133,10 @@ def lambdafunc(seq):
# **should be filtered down to:**
#
# ['soup','salad']

seq = ['soup','dog','salad','cat','great']
list(filter(lamda word: word[0]=='s', seq.split()))


return None

Expand All @@ -114,6 +149,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. **

if (speed<=60):
print("No ticket")
if ( 61<=speed<=80):
print("Small Ticket")
if ( speed>=80):
print("Big ticket")
else(is-_birthday=='Yes"):
print("True"):


return None

Expand All @@ -128,6 +173,8 @@ def create_arr_of_fives():
#### Create an array of 10 fives
#### Convert your output into list
#### e.g return list(arr)
ar = np.fives(5)
list(ar)

return None

Expand All @@ -138,6 +185,8 @@ 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)
ar = np.arrange[10,50,2]
list(ar)

return None

Expand All @@ -148,6 +197,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()
ar = np.arrange(9)
ar.reshape(3,3)
return (ar).tolist()

return None

Expand All @@ -158,6 +210,9 @@ 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)
ar=np.linspace(0,1,20)
list(ar)


return None

Expand All @@ -168,6 +223,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()
ar=np.arrange(0.01,1).reshape(10,10)
return (ar).tolist()


return None

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


return None


Expand All @@ -210,6 +269,9 @@ def slices_2():
# array([[ 2],
# [ 7],
# [12]])
arr2=(arr[0:3,1])
return (arr2).tolist()


return None

Expand All @@ -230,6 +292,10 @@ def slices_3():
### e.g return (arr).tolist()
# array([[16, 17, 18, 19, 20],
# [21, 22, 23, 24, 25]])
arr2=(arr[0:3,4])




return None

Expand Down