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 #156

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
76 changes: 67 additions & 9 deletions Python_Exercises.py
Original file line number Diff line number Diff line change
Expand Up @@ -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



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


return None


Expand All @@ -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


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]
d = lst[3][1][2][0]
print(d)

return None

Expand All @@ -52,15 +60,18 @@ 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


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

Expand All @@ -74,21 +85,30 @@ def domainGet(email):
# [email protected]
#
# **So for example, passing "[email protected]" would return: domain.com**
z='[email protected]'
x=z.split("@")[-1]
print(x)


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

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


Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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


Expand All @@ -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

Expand All @@ -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

Expand Down