Commit 1627b6fc authored by Ian Stump's avatar Ian Stump

Merge branch 'week2day5' into 'master'

Week2day5

See merge request !2
parents 7ed8b992 5464e298
<!DOCTYPE html> <!-- just to say we want to use html site -->
<html lang="en">
<!-- defines main language of website -->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- width device width is to make usre that it adapts to mobile/different screen sizes -->
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- to link the CSS file - we use link tag in the head -->
<title>Document</title> <!-- tittle of tab -->
</head>
<body>
</body>
</html>
<!-- head is for server and crawlers ; has meta data, SEO etc -->
<!-- search engines do not understand semantics so we need to use good practices, so that things are read as , e.g. if they see a button class (CSS) crawlers from search engines and disbaled user tools (screen readers) will know that is a "button", if button is made with div they will not know -->
<!-- div - main use for the is to split things; one interview question was to write a button, so thye see if you use a class (which you should) -->
<!-- p - is paragraph -->
<!-- span - different than div, bc it tkaes only the space it needs, can also be used to apply styles to specific words in a text -->
<!-- CSS RESET - copy paste it to my website to reset any browser specific styles -->
<!-- shoudl only have 2 types of clickable elements in website: anchor link (rediects to new page); and button -->
<!-- aside tag to put nav menus on the side of the page -->
<!-- hr - thematic break-->
<!-- form tag to submit information always need to wrap i tin this tag -->
<!-- google chrome - got to inspect element -- AUDIT -- gives us pointers to improve website -->
<!--CSS -->
<!--to add style we can add in a file in CSS, in a style tag in the html file (in the head), in the tags themselves; but best practice is to use CSS -->
<!-- in CSS order maters within each type (ID, class, tag), but there is a priority order between different categories: ID first, class second, tag third-->
<!-- display: inline, block and inline block - inline block allows to define margin and if we are applying it to a span tag, so we cna change the width and height a little -->
<!-- flex display is REALLY IMPORTANT-->
<!-- positions: STATIC(default), FIXED (relative to the viewport of the browser - ie always y=0, x=10px to the left), ABSOLUTE - relative to the body always, independent of parents - RELATIVE, changes it relative to the body OR the parent tag if the parent is not static (ie, has a class / a margin)-->
<!-- the best position is relative; for absolute or fixed elements, sometimes mobiles do not show them right while scrolling, bc these are outside the flow of a website-->
<!-- FLEX-->
<!-- FLEX, display flex , will add a flex direction automatically to row (not visible) - we can overwrite this with "flex-direction:column"-->
<!-- div tag always takes the width of the page, but height only as specified-->
<!-- screen readers will ALWAYS read semantics from html orders; if we change positions just using style, e.g. flex-direction", screen readers will not see that visual change but stick to what is in the html-->
<!-- justify content -- moves in the X axis; align items -- moves on the Y axis; they apply to all flex class paren, children-->
<!-- order and align self ( flex end) - child flex properties -->
<!-- LOOK AT "CAN I USE.COM" TO SEE WHAT CSS PROPERTIES SPECIFIC BROWSERS ACCEPT -->
<!-- MEDIA QUERIES-->
<!-- to apply styles based on size of the screen-->
<!-- BEM-->
<!--interview question: if we know some CSS framework. answer: BEM-->
<!--GRID LAYOUT-->
<!-- display: grid ;; allows to tell the elements hw to use the space, by defining how many ros and columns; it is an alternative to flex, better than flex for layouts-->
\ No newline at end of file
def count_repetition(array):
result = {}
for writer in array:
if writer in result:
result[writer] += 1
else:
result[writer] = 1
return result
"""
#WIP with nested loops
#method 1
def count_repetition(array):
result = {}
for x in range(len(array)):
for y in range(x + 1, len(array)):
# print(array[x], array[y]) #--the loop is working
count=2
if array[x] == array[y]:
print(array[x], array[y]) # it is getting the right amount of pairs
count +=1 # the COUNT is not right...
print(count)
result[array[x]]= count
#print(count)
else:
result[array[x]] = 1
return result
#method 2
def count_repetition(array):
result = {}
for x in array:
for y in array[1::]:
# print(x, y) #--the loop is working
count = 1
if x == y :
print(x, y)
count += 1 # the COUNT is not right...
print(count)
result[x] = count
#print(count)
else:
result[x] = count
return result
"""
names = ['kerouac', 'fante', 'fante', 'buk', 'hemingway', 'hornby', 'kerouac', 'buk', 'fante']
print(count_repetition(names))
# {'kerouac': 2, 'fante': 3, 'buk': 2, 'hemingway': 1, 'hornby': 1}
def exp_recursive(base, exp):
if exp ==0:
return 1
else:
return base*exp_recursive(base, exp-1)
print(exp_recursive(5, 3)) # 125
print(exp_recursive(2, 4)) # 16
print(exp_recursive(5, 1)) # 5
print(exp_recursive(6, 0)) # 1
\ No newline at end of file
def is_array_or_tuple(arg):
if isinstance(arg,list) or isinstance(arg, tuple):
return True
else:
return False
print(is_array_or_tuple('hello')) # False
print(is_array_or_tuple(['hello'])) # True
print(is_array_or_tuple([2, {}, 10])) # True
print(is_array_or_tuple({'a': 2})) # False
print(is_array_or_tuple((1, 2))) # True
print(is_array_or_tuple(set())) # False
\ No newline at end of file
def are_same_type(array):
for x in array:
for y in array:
if type(x) != type(y):
return False
else:
return True
print(are_same_type(['hello', 'world', 'long sentence'])) # True
print(are_same_type([1, 2, 9, 10])) # True
print(are_same_type([['hello'], 'hello', ['bye']])) # False
print(are_same_type([['hello'], [1, 2, 3], [{'a': 2}]])) # True
print(are_same_type([['hello'], set('hello')])) # False
\ No newline at end of file
def is_only_string(string):
if type(string) == str: #isinstance(string, str):
for element in string:
if element == " " or element.isdigit():
return False
return True
else:
return False
print(is_only_string('11')) # False
print(is_only_string('hello')) #True
print(is_only_string(['hello'])) # ? Please handle this case!! Should return False
print(is_only_string('this is a long sentence')) # False
print(is_only_string({'a': 2})) # ? Please handle this case!! Should return False
\ No newline at end of file
def bank(D,W):
return net_amount
print (bank([200, 200, 300], [200]))
print (bank([400,300], [200]))
#print(sum([[1,2]]))
"""
def bank(D,W):
deposit_array = []
deposit_total = deposit_array.extend(D)
#print(deposit_array)
deposit= sum(deposit_total)
print(deposit)
withdraw_array =[]
withdraw_total=withdraw_array.extend(W)
withdraw=sum(withdraw_total)
net_amount = deposit-withdraw
return net_amount
print (bank([400,300], [200]))
"""
def new_dict(array):
result={}
for x in array:
result[x]
#for key in result.keys():
return result
print(new_dict([1, 2, 3, 4, 5])) # {1: {2: {3: {4: {5: {}}}}}}
\ No newline at end of file
def nt_dictionary(num):
import random
dictionary={}
for key in range(num): #bc exercise states that the number of keys is equal to the input num
while True:
new_key = random.randint(1, 1000) # setting the key
if new_key in dictionary.keys(): #check this logic
continue #check this logic
break #check this logic
dictionary[new_key]= new_key**2 #setting the value
return dictionary
print(nt_dictionary(20))
print('Length', len(nt_dictionary(20)))
\ No newline at end of file
#TO DO the manual way
#the package inflect can do this
def write_number(num):
import inflect
p = inflect.engine()
result = p.write_number()
return result
write_number(11) # "eleven"
write_number(2) # "two"
write_number(32) # "thirty-two"
\ No newline at end of file
def is_caught(arg):
if arg.index("C") >= arg.index("m")-3:
return True
else:
return False
print(is_caught('C.....m')) # False
print(is_caught('C..m')) # True
print(is_caught('..C..m')) # True
print(is_caught('...C...m')) # False
print(is_caught('C.m')) # True
\ No newline at end of file
def convert(args):
result=[]
#convert to an iterable str
args_iterable=str(args)
for element in args_iterable:
#convert each string a=element to integer
result.append(int(element))
a = sorted(result)
b= a[::-1]
return b
print(convert(429563)) # [9, 6, 5, 4, 3, 2]
print(convert(324)) # [4, 3, 2]
\ No newline at end of file
def letter_counter(string):
count_upper=0
count_lower=0
for x in string:
if x.isupper():
count_upper+=1
elif x.islower():
count_lower+=1
print ("UPPER CASE" + str(count_upper) + "/ LOWER CASE" + str(count_lower))
letter_counter("Hello World!")
# Hello World!
# UPPER CASE 2
# LOWER CASE 8
def is_alphanumeric(str):
for element in str:
if type(element) == str or element.isdigit():
return True
elif element == " ":
return False
else:
return False
print(is_alphanumeric('11')) # True
print(is_alphanumeric(['hello'])) # False
print(is_alphanumeric('this is a long sentence')) # False
print(is_alphanumeric({'a': 2})) # False
print(is_alphanumeric("this is string....!!!")) # False
def intersection(a,b):
new_string =a + b
sorted_string=sorted(new_string)
result=""
for x in sorted_string:
if x not in result:
result +=x
return result
#to check if the inputs are only letters (ie no spaces or digits) AND if they are not equal
a = 'xyaabbbccccdefww'
b = 'xxxxyyyyabklmopq'
x = 'abcdefghijklmnopqrstuvwxyz'
print(intersection(a, b)) # abcdefklmopqwxy
print(intersection(a, x)) # abcdefghijklmnopqrstuvwxyz
\ No newline at end of file
def split_the_bill(arg):
sum=0
result={}
for value in arg.values(): #iterate through values
sum+=value
average = sum/len(arg)
print(average)
#itarate through whole object and replace the values of the keys:
for key, value in arg.items():
result[key] =value- average
return result
group = {
'Amy': 20,
'Bill': 15,
'Chris': 10
}
print(split_the_bill(group)) # { 'Amy': -5, 'Bill': 0, 'Chris': 5 }
def is_string(string):
if isinstance(string, str):
print (True)
else:
print (False)
is_string("hello")
is_string(13)
def zero_sum(array):
result=[]
for x in array:
for y in array[1::]:
#print(array[x],array[y])
if x== -y :
output=[array.index(x),array.index(y)]
reverse_output= output[::-1]
#bc of NOTE below ahd to create an interim array and see if those modules existed already in the nested module results object
if output not in result and reverse_output not in result:
result.append(output)
#result.append([array.index(x),array.index(y)])
return result
print(zero_sum([1, 5, 0, -5, 3, -1])) # [[0, 5], [1, 3], [2, 2]]
print(zero_sum([1, -1])) # [[0, 1]]
print(zero_sum([0, 4, 3, 5])) # [[0, 0]]
"""
#NOTE: in a nested array, or nested tutle, not in only recognized exact modules and does not see numbers inside nested modules
#tests to demonstrate the above
def test(array):
if (array) not in [[2, 3], (5, 6), 9, 1]:
return False
else:
return True
print (test([2,3]))
print (test([3,2]))
print (test(2))
print (test(9))
"""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment