├── Week-1 ├── arithmetic.py ├── builtin-functions.py ├── data_types.py ├── hello.py └── variables.py ├── Week-2 ├── arithmetic_operators.py ├── comparison_operators.py ├── conditionals.py ├── data_types.py ├── logical_operators.py ├── notes.md ├── string_sample_excercise.py ├── strings.py └── type-conversion.py ├── Week-3 ├── getting-item-in-list.py ├── list-example.py ├── lists.py ├── modify-list-using-list-method.py ├── modifying-list.py └── notes.md ├── Week-4 ├── for-loop.py ├── functions.py └── while-loop.py └── Week-5 ├── HOF.py ├── dictionaries.py ├── exercises.py ├── functions.py ├── lambda_functions.py ├── list_dictionaries.py ├── notes.md ├── sets.py └── tuple.py /Week-1/arithmetic.py: -------------------------------------------------------------------------------- 1 | # this is a comment 2 | # commen makes code more readable 3 | 4 | # the print() function takes unlimited number of inputes and gives an output 5 | print(1 + 2, 3 - 1, 2 * 3, 3 / 2, 2 ** 10) 6 | print('The sum is ', 1 + 2) 7 | print('The difference is ', 2 - 1) 8 | print('The product is ', 2 * 3) 9 | print('The division ', 3 / 2) 10 | print('The remainder is ', 5 % 3) 11 | print('The floor division', 9 // 2) -------------------------------------------------------------------------------- /Week-1/builtin-functions.py: -------------------------------------------------------------------------------- 1 | # print(), type(), len(), round(), int(), float(), input() 2 | 3 | # print() takes unlimited input and return the output 4 | from decimal import ROUND_UP 5 | 6 | 7 | print(1, '2', True, 'Asabeneh', [1, 1, 2,]) 8 | print(type('2')) 9 | print(type([1, 2])) 10 | print(len('cat')) 11 | print(len('cat') ==len('car')) 12 | print(len('Python') == len('Dragon')) 13 | print('Python'.endswith('on') == 'Dragon'.endswith('o')) 14 | 15 | print(round(4 / 3, 4)) 16 | print(int('2')) 17 | print(float('9.812')) 18 | 19 | year_born = input('What year were you born? ') 20 | current_year = 2022 21 | print(type(year_born)) 22 | 23 | age = current_year - int(year_born) 24 | print(age) 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Week-1/data_types.py: -------------------------------------------------------------------------------- 1 | # What are the available data types we have in Python? 2 | # Numbers(inter, float, complex), Strings, Booleans(True or False), 3 | # List 4 | # ['Finland', 'Sweden', 'Denmark', 'Norway','Iceland'] => list 5 | # ('Finland', 'Sweden', 'Denmark', 'Norway','Iceland') => tuple 6 | # {'Finland', 'Sweden', 'Denmark', 'Norway','Iceland'} 7 | # {'Finland':'Helsinki', 'Sweden':'Stockholm', 'Denmark':'Copenhagen', 'Norway':'Oslo,'Iceland':'Ry'} 8 | # {'book':'kirja','house':'talo', 'student':'opiskelija'} 9 | 10 | # All this are number type data types 11 | print(1, type(1)) # int 12 | print(1.2, type(1.2)) # float 13 | print(10, type(10)) # int 14 | print(9.81, type(9.81)) # float 15 | print(1 + 2j, type(1 + 2j)) # complex number 16 | 17 | # Booleans are True or False 18 | print(True, type(True)) 19 | print(False, type(False)) 20 | print(2 > 1, type(2 > 1)) 21 | print(2 < 1, type(2 < 1)) 22 | print(2 == 1, type(2 == 1)) 23 | print(2 == int('2')) 24 | print(str(2) == '2') 25 | 26 | # Strings 27 | print('Asabeneh', type('Asabeneh')) 28 | print('Do you know that I love Python') 29 | 30 | # List 31 | print([1, 2, 3, 4], type([1, 2, 3, 4])) 32 | print(['Milk','Meat','Sugar','Coffe'], type(['Milk','Meat','Sugar','Coffe'])) 33 | 34 | # Tuple 35 | 36 | print(('Milk','Meat','Sugar','Coffe'), type(('Milk','Meat','Sugar','Coffe'))) 37 | 38 | # Set 39 | print({'Milk','Meat','Sugar','Coffe'}, type({'Milk','Meat','Sugar','Coffe'})) 40 | 41 | # Dictionary 42 | print({'book':'kirja','house':'talo', 'student':'opiskelija'}, type({'book':'kirja','house':'talo', 'student':'opiskelija'})) -------------------------------------------------------------------------------- /Week-1/hello.py: -------------------------------------------------------------------------------- 1 | print('Hello') 2 | print('Hello everyone!') 3 | print('Hello Python!') 4 | print('All my students love Python so very much!') 5 | print(10 + 2) 6 | print(2 * 3) 7 | print('Visual studio made coding much greater than ever before') 8 | print('Asabeneh', 'Yetayeh', 250, 'Finland', True, ['Python','JavaScript','Flying']) 9 | -------------------------------------------------------------------------------- /Week-1/variables.py: -------------------------------------------------------------------------------- 1 | # variables 2 | # variables are a place to store data 3 | # not allowed to use special characters as variable name except underscore 4 | # you cannot start a variable with a number 5 | # there is shoulb space in a variable naem 6 | 7 | first_name = 'Asabeneh' 8 | last_name = 'Yetayeh' 9 | country = 'Finland' 10 | city = 'Helsinki' 11 | age = 250 12 | full_name = first_name + ' ' + last_name 13 | print(full_name) 14 | 15 | print('I am ' + full_name + '.' + 'I am ' + str(age) + ' years old. ' + 'I live in ' + country) 16 | print(f'I am {full_name}. I am {age} years old. I live in {city}, {country}') 17 | 18 | 19 | # I am Asabeneh Yetayeh. I am 250 years old. I live in Finland. 20 | 21 | a = 4 22 | b = 3 23 | 24 | print(f'The sum of {a} and {b} is {a + b}') 25 | print(f'The difference of {a} and {b} is {a - b}') 26 | print(f'The product of {a} and {b} is {a * b}') 27 | print(f'The division of {a} and {b} is {a / b}') 28 | -------------------------------------------------------------------------------- /Week-2/arithmetic_operators.py: -------------------------------------------------------------------------------- 1 | # Arithmetics(+, -, * , /, %, //, **) 2 | print('addition:', 1 + 2) 3 | print('subtraction:', 2 - 1) 4 | print(2 * 3) 5 | print(2 * 2 * 2 * 2 * 2) 6 | print(2 ** 5) 7 | print(4 % 4) 8 | print(4 % 2) 9 | print(4 % 1) 10 | print(4 % 3) 11 | print(7 % 5) 12 | print(4 // 4) 13 | print(3 // 2) 14 | print(5 // 2) 15 | print(9 // 5) -------------------------------------------------------------------------------- /Week-2/comparison_operators.py: -------------------------------------------------------------------------------- 1 | print(2 > 1) 2 | print(2 >= 1) 3 | print(2 < 1) 4 | print(2 <= 1 ) 5 | print(2 == 2) 6 | print(2 == '2') 7 | print(2 is 2) 8 | print(2 is not 4) 9 | print(True == True) 10 | print(False == False) 11 | 12 | 13 | -------------------------------------------------------------------------------- /Week-2/conditionals.py: -------------------------------------------------------------------------------- 1 | ''' a = 5 2 | 3 | if a > 0: 4 | print('a is positive') 5 | else: 6 | print('Negative') 7 | ''' 8 | 9 | x = 10 10 | if x > 0: 11 | print(f'{x} is a postive number') 12 | elif x == 0: 13 | print(f'{x} is zero') 14 | else: 15 | print(f'{x} is a negative number') 16 | 17 | weather = input('What is the weather like? ').lower() 18 | if weather == 'rainy': 19 | print('Please take a raincoat') 20 | elif weather == 'stormy': 21 | print('Take care of yourself') 22 | elif weather == 'cloudy': 23 | print('It might rain') 24 | elif weather == 'sunny': 25 | print('It is a shiny day and go out freely') 26 | elif weather == 'snowy': 27 | print('It will be very slippery') 28 | else: 29 | print('No one knows the weather') 30 | -------------------------------------------------------------------------------- /Week-2/data_types.py: -------------------------------------------------------------------------------- 1 | # Number(Int, Float, Complex) 2 | # String 3 | # Booleans 4 | # List -> ['Potato', 'Tomato', 'Milk', 'Meat'] 5 | # Set 6 | # Tuple 7 | # Dictionary 8 | 9 | 10 | a = 5 11 | name = 'John' 12 | gravity = 9.81 13 | is_married = True 14 | cpx = 10 + 4j 15 | 16 | shopping_list = ['Potato','Tomato','Milk','Meat'] 17 | print(a, 'type:', type(a)) 18 | print(name, 'type:', type(name)) 19 | print(gravity, 'type:', type(gravity)) 20 | print(cpx, 'type:', type(cpx)) 21 | print(is_married, 'type:', type(is_married)) 22 | print(shopping_list, 'type:', type(shopping_list)) 23 | -------------------------------------------------------------------------------- /Week-2/logical_operators.py: -------------------------------------------------------------------------------- 1 | # and or not 2 | 3 | # and 4 | print('=== this is the and part ===') 5 | print(2 > 1 and 4 > 3) 6 | print(2 > 1 and 4 < 3) 7 | print(2 < 1 and 4 < 3) 8 | 9 | # or 10 | print('=== The is is or part ===') 11 | print(2 > 1 or 4 > 3) 12 | print(2 > 1 or 4 < 3) 13 | print(2 < 1 or 4 < 3) 14 | 15 | # Not -> Negation He is a boy => He is not a boy 16 | print('=== THis is the negation ==== ') 17 | print(2 > 1) 18 | print(not 2 > 1) 19 | print(not not 2 > 1) 20 | -------------------------------------------------------------------------------- /Week-2/notes.md: -------------------------------------------------------------------------------- 1 | # Operators 2 | 3 | - Arithmetic Operators 4 | - Comparison Operators 5 | - Logical Operators 6 | 7 | # Strings 8 | 9 | # List 10 | 11 | # Conditional 12 | 13 | # Loops -------------------------------------------------------------------------------- /Week-2/string_sample_excercise.py: -------------------------------------------------------------------------------- 1 | # What are strings? 2 | # A string is a text any data under a single, double, triple quote can be considered as a string 3 | # how long is a string, it a single character or many many pages 4 | 5 | 6 | letter = 'a' 7 | print(len(letter)) 8 | word = 'python' 9 | print(word, len(word)) 10 | sentence = 'Python is great' 11 | print(sentence, len(sentence)) 12 | 13 | words = sentence.split() 14 | print(len(words)) 15 | 16 | first_name = 'Asabeneh' 17 | print(first_name.lower()) 18 | print(first_name.upper()) 19 | # Sample dna generated using this online tool: http://www.faculty.ucr.edu/~mmaduro/random.htm 20 | dna = 'GCTTTGCGCCATAATTCCAATGAAAAACCTATGCACTTTGTTTAGGGTACCATCAGGAATCTGAACCCTCAGATAGTGGGGATCCCGGGTATAGACCTTTATCTGCGGTCCAACTTAGGCATAAACCTGCATGCTACCTTGTCAGACCCACTCTGCACGAAGTAAATATGGGATGCGTCCGACCTGGCTCCTGGCGTTCCACGCCGCCACGTGTTCGTTAACTGTTGATTGGTGGCACATAAGTAATACCATGGTCCCTGAAATTCGGCTCAGTTACTTCGAGCGTAATGTCTCAAATGGCGTAGAACGGCAATGACTGTTTGACACTAGGTGGTGTTCAGTTCGGTAACGGAGAGTCTGTGCGGCATTCTTATTAATACATTTGAAACGCGCCCAACTGACGCTAGGCAAGTCAGTGCAGGCTCCCGTGTTAGGATAAGGGTAAACATACAAGTCGATAGAAGATGGGTAGGGGCCTTCAATTCATCCAGCACTCTACGGTTCCTCCGAGAGCAAGTAGGGCACCCTGTAGTTCGAAGGGGAACTATTTCGTGGGGCGAGCCCACACCGTCTCTTCTGCGGAAGACTTAACACGTTAGGGAGGTGGAATAGTTTCGAACGATGGTTATTAATCGTAATAACGGAACGCTGTCTGGAGGATGAGTCTGACGGTGTGTAACTCGATCAGTCACTCGCTATTCGAACTGCGCGAAAGATCCCAGCGCTCATGCACTTGATTCCGAGGCCTGTCCCGATATATGAACCCAAACTAGAGCGGGGCTGTTGACGTTTGGAGTTGAAAAAATCTATTATACCAATCGGCTTCAACGTGCTCCACGGCAGGCGCCTGACGAGGGGCCCACACCGAGGAAGTAGACTGTTGCACGTTGGGGATAGCGCTAGCTAACAAAGACGCCTGCTACAACAGGAGTATCAAACCCGTACAAAGGGAACATCCACACTTTGGTGAATCGAAGCGCGGCATCAGGATTTCCTTTTG' 21 | 22 | num_a = dna.count('A') 23 | num_t = dna.count('T') 24 | num_g = dna.count('G') 25 | num_c = dna.count('C') 26 | total = len(dna) 27 | print(num_a / total) 28 | -------------------------------------------------------------------------------- /Week-2/strings.py: -------------------------------------------------------------------------------- 1 | # What are strings? 2 | # A string is a text any data under a single, double, triple quote can be considered as a string 3 | # how long is a string, it a single character or many many pages 4 | 5 | 6 | from itertools import count 7 | 8 | 9 | letter = 'a' 10 | print(len(letter)) 11 | word = 'python' 12 | print(word, len(word)) 13 | sentence = 'Python is great' 14 | print(sentence, len(sentence)) 15 | 16 | words = sentence.split() 17 | print(len(words)) 18 | 19 | first_name = 'Asabeneh' 20 | print(first_name.lower()) 21 | print(first_name.upper()) 22 | 23 | # split(), lower, upper(), count(), starswith(), endswith(), title(), swapcase() 24 | print('land' in 'Finland') 25 | print('Tea' in ['Milk','Potatop','Tea','Sugar']) 26 | 27 | country = 'Finland' 28 | print(country.startswith('Fin')) 29 | print(country.endswith('land')) 30 | 31 | first_name = 'Asabeneh' 32 | last_name = 'Yetyeh' 33 | age = 250 34 | country = 'Finland' 35 | city = 'Helsinki' 36 | full_name = first_name + ' ' + last_name 37 | 38 | print(full_name) 39 | 40 | print('My name is ' + full_name + '. ' + 'I live in ' + city + ', ' + country + '. ' + 'I am ' + str(age) + ' years old.') 41 | 42 | print(f'My name is {full_name}. I live in {city}, {country}. I am {age} years old.') 43 | 44 | # My name is Asabeneh Yetayeh. I live in Helsinki, Finland. I am 250 years old. 45 | 46 | a = 4 47 | b = 3 48 | print(f'The sum of {a} and {b} is {a + b}') 49 | print('The sum of {} and {} is {}'.format(a, b, a + b)) 50 | print(f'The difference of {a} and {b} is {a - b}') 51 | print(f'The product of {a} and {b} is {a * b}') 52 | print(f'The division of {a} and {b} is {a / b :.3f}') 53 | print(f'The modules of {a} and {b} is {a % b}') 54 | print(f'The floor division of {a} and {b} is {a // b}') 55 | print(f'The power of {a} and {b} is {a ** b}') 56 | 57 | word = 'Python' 58 | print(word[0]) 59 | print(word[1]) 60 | print(word[2]) 61 | print(word[3]) 62 | print(word[4]) 63 | print(word[5]) 64 | last_index = len(word) - 1 65 | print(word[last_index]) 66 | 67 | print(word[-1]) 68 | print(word[-2]) 69 | print(word[4] == word[-2]) 70 | print(word[1:]) 71 | print(word[0:2]) 72 | print(word[2:]) 73 | print(word[-4:]) -------------------------------------------------------------------------------- /Week-2/type-conversion.py: -------------------------------------------------------------------------------- 1 | num_int = 2 2 | print(num_int, type(num_int)) 3 | num_str = str(num_int) 4 | print(type(num_str)) 5 | 6 | num_str = '10' 7 | print(num_str, type(num_str)) 8 | num_int = int(num_str) 9 | print(num_int, type(num_int)) 10 | 11 | gravity_str = '9.81' 12 | print(gravity_str, type(gravity_str)) 13 | 14 | gravity_num = float(gravity_str) 15 | print(gravity_num, type(gravity_num)) 16 | 17 | print(str(2) == '2') 18 | print(2 == int('2')) 19 | print(float(2) == float('2')) 20 | 21 | test = '9.81' 22 | print(int(float(test))) 23 | 24 | -------------------------------------------------------------------------------- /Week-3/getting-item-in-list.py: -------------------------------------------------------------------------------- 1 | lst = [1, 2, 3, 4, 5] 2 | print(len(lst), lst) 3 | print(lst[0]) 4 | print(lst[1]) 5 | print(lst[2]) 6 | print(lst[3]) 7 | print(lst[4]) 8 | 9 | last_index = len(lst) - 1 10 | print('The last index is:', last_index) 11 | print('The last item is:', lst[last_index]) 12 | print('The last item is ', lst[-1]) 13 | print(lst[-2]) 14 | 15 | # Slicing:start index and ending index but it does not include the item of the ending index 16 | print(lst[1:4]) 17 | print(lst[2:4]) 18 | print(lst[3:]) 19 | print(lst[-4:-2]) 20 | -------------------------------------------------------------------------------- /Week-3/list-example.py: -------------------------------------------------------------------------------- 1 | # List is a collection of items 2 | 3 | nums = [1, 2, 3, 4] 4 | print(len(nums), nums) 5 | evens = [0, 2, 4, 6] 6 | odds = [1, 3, 5, 7] 7 | integers = [ -3, -2, -1, 0, 1, 2, 3] 8 | print(len(integers)) 9 | countries = ['Finland','Sweden','Denmark','Iceland','Norway'] 10 | print(len(countries)) 11 | 12 | lst = [] # or you can create an empty list like this: list() 13 | print(len(lst), lst) 14 | names = ['Bill Gages','Steve Jobs','Donald Trump','Joe Biden'] 15 | shopping_list = ['Milk','Coffee','Tomatop','Potato'] -------------------------------------------------------------------------------- /Week-3/lists.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Week-3/modify-list-using-list-method.py: -------------------------------------------------------------------------------- 1 | """ 2 | lst = [1, 2, 3] 3 | print('Number of items in the list:', len(lst), lst) 4 | # Append mehtod to add an item 5 | lst.append(4) 6 | lst.append(100) 7 | lst.append('Milk') 8 | lst.append(200) 9 | lst.extend([7, 8, 9, 10]) 10 | print('Number of items in the list:', len(lst), lst) 11 | 12 | num1 = [1, 2, 3] 13 | num2 = [4, 5, 6] 14 | num1_2 = num1 + num2 15 | print(num1_2) 16 | """ 17 | 18 | 19 | from numpy import number 20 | 21 | 22 | nums = [1, 2, 3] 23 | 24 | print('Number of items in the list:', len(nums), nums) 25 | nums.insert(1, 9.81) 26 | print('Number of items in the list:', len(nums), nums) 27 | nums.insert(3, 3.14) 28 | print('Number of items in the list:', len(nums), nums) 29 | nums.insert(0, 'item 1') 30 | print('Number of items in the list:', len(nums), nums) 31 | 32 | countries = ['Finland','Sweden','Denmark','Iceland','Norway'] 33 | print('Number of items in the list:', len(countries), countries) 34 | countries.pop() # without an argument it remove the last item 35 | countries.pop(2) # remove the item with corrosponding index 36 | print('Number of items in the list:', len(countries), countries) 37 | 38 | countries = ['Finland','Sweden','Denmark','Iceland','Norway'] 39 | print('Number of items in the list:', len(countries), countries) 40 | # let modify this countries list using remove 41 | 42 | countries.remove('Iceland') 43 | print('Number of items in the list:', len(countries), countries) 44 | 45 | # del 46 | 47 | countries = ['Finland','Sweden','Denmark','Iceland','Norway'] 48 | print('Number of items in the list:', len(countries), countries) 49 | del countries[1:3] 50 | print('Number of items in the list:', len(countries), countries) 51 | 52 | # Reverse list 53 | countries = ['Finland','Sweden','Denmark','Iceland','Norway'] 54 | print('Number of items in the list:', len(countries), countries) 55 | countries.reverse() 56 | 57 | print('Number of items in the list:', len(countries), countries) 58 | # sort 59 | countries = ['Finland','Sweden','Denmark','Iceland','Norway'] 60 | print('Number of items in the list:', len(countries), countries) 61 | countries.sort(reverse=True) 62 | print('Number of items in the list:', len(countries), countries) 63 | numbers = [9.81, 3.14, 2.27, 100, 6.23] 64 | numbers.sort(reverse=True) 65 | print(numbers) 66 | 67 | # sorted builtin function 68 | countries = ['Finland','Sweden','Denmark','Iceland','Norway'] 69 | print('Number of items in the list:', len(countries), countries) 70 | copy_of_countries = countries.copy() 71 | sorted_countries = sorted(countries) 72 | print('Number of items in the list:', len(countries), countries) 73 | print(sorted_countries) 74 | # Notice the difference between sort method and sorted builtin function 75 | 76 | copy_of_countries.append('Marsland') 77 | print(countries) 78 | 79 | print('Finland' in countries) 80 | 81 | if 'Norway' in countries: 82 | print('The index of finland is ', countries.index('Norway')) 83 | else: 84 | print('Estonia is not in the list') 85 | 86 | -------------------------------------------------------------------------------- /Week-3/modifying-list.py: -------------------------------------------------------------------------------- 1 | lst = [1, 2, 3] 2 | print('Number of items in the list:', len(lst), lst) 3 | lst[0] = 9.81 4 | 5 | print('Number of items in the list:', len(lst), lst) 6 | lst[2] = 'Milk' 7 | 8 | print('Number of items in the list:', len(lst), lst) 9 | 10 | -------------------------------------------------------------------------------- /Week-3/notes.md: -------------------------------------------------------------------------------- 1 | # List 2 | # Loops 3 | # Functions 4 | 5 | 6 | # Tuples, Set Dictionary -------------------------------------------------------------------------------- /Week-4/for-loop.py: -------------------------------------------------------------------------------- 1 | ''' 2 | evens = [] 3 | for i in range(101): 4 | if i % 2 == 0: 5 | evens.append(i) 6 | 7 | print(evens) 8 | 9 | 10 | odds = [] 11 | for i in range(101): 12 | if i % 2 != 0: 13 | odds.append(i) 14 | 15 | print(odds) 16 | 17 | total = 0 18 | for i in range(101): 19 | total = total + i 20 | 21 | print(total) 22 | nums = list(range(101)) 23 | print(nums) 24 | print(sum(nums)) 25 | ''' 26 | # for loop 27 | 28 | ''' for i in range(101): 29 | print(f'{i} x {i} = {i * i}') 30 | 31 | for i in range(10, -1, -1): 32 | print(i) ''' 33 | 34 | countries = ['Finland','Sweden','Denmark','Iceland','Norway'] 35 | 36 | for n in [10, 21, 30, 44, 51]: 37 | print(n) 38 | 39 | lst_lst = [] 40 | for country in countries: 41 | lst_lst.append([country.upper(),country.upper()[0:3],len(country)]) 42 | 43 | print(lst_lst) 44 | 45 | countries = [ 46 | 'Afghanistan', 47 | 'Albania', 48 | 'Algeria', 49 | 'Andorra', 50 | 'Angola', 51 | 'Antigua and Barbuda', 52 | 'Argentina', 53 | 'Armenia', 54 | 'Australia', 55 | 'Austria', 56 | 'Azerbaijan', 57 | 'Bahamas', 58 | 'Bahrain', 59 | 'Bangladesh', 60 | 'Barbados', 61 | 'Belarus', 62 | 'Belgium', 63 | 'Belize', 64 | 'Benin', 65 | 'Bhutan', 66 | 'Bolivia', 67 | 'Bosnia and Herzegovina', 68 | 'Botswana', 69 | 'Brazil', 70 | 'Brunei', 71 | 'Bulgaria', 72 | 'Burkina Faso', 73 | 'Burundi', 74 | 'Cambodia', 75 | 'Cameroon', 76 | 'Canada', 77 | 'Cape Verde', 78 | 'Central African Republic', 79 | 'Chad', 80 | 'Chile', 81 | 'China', 82 | 'Colombi', 83 | 'Comoros', 84 | 'Congo (Brazzaville)', 85 | 'Congo', 86 | 'Costa Rica', 87 | "Cote d'Ivoire", 88 | 'Croatia', 89 | 'Cuba', 90 | 'Cyprus', 91 | 'Czech Republic', 92 | 'Denmark', 93 | 'Djibouti', 94 | 'Dominica', 95 | 'Dominican Republic', 96 | 'East Timor (Timor Timur)', 97 | 'Ecuador', 98 | 'Egypt', 99 | 'El Salvador', 100 | 'Equatorial Guinea', 101 | 'Eritrea', 102 | 'Estonia', 103 | 'Ethiopia', 104 | 'Fiji', 105 | 'Finland', 106 | 'France', 107 | 'Gabon', 108 | 'Gambia, The', 109 | 'Georgia', 110 | 'Germany', 111 | 'Ghana', 112 | 'Greece', 113 | 'Grenada', 114 | 'Guatemala', 115 | 'Guinea', 116 | 'Guinea-Bissau', 117 | 'Guyana', 118 | 'Haiti', 119 | 'Honduras', 120 | 'Hungary', 121 | 'Iceland', 122 | 'India', 123 | 'Indonesia', 124 | 'Iran', 125 | 'Iraq', 126 | 'Ireland', 127 | 'Israel', 128 | 'Italy', 129 | 'Jamaica', 130 | 'Japan', 131 | 'Jordan', 132 | 'Kazakhstan', 133 | 'Kenya', 134 | 'Kiribati', 135 | 'Korea, North', 136 | 'Korea, South', 137 | 'Kuwait', 138 | 'Kyrgyzstan', 139 | 'Laos', 140 | 'Latvia', 141 | 'Lebanon', 142 | 'Lesotho', 143 | 'Liberia', 144 | 'Libya', 145 | 'Liechtenstein', 146 | 'Lithuania', 147 | 'Luxembourg', 148 | 'Macedonia', 149 | 'Madagascar', 150 | 'Malawi', 151 | 'Malaysia', 152 | 'Maldives', 153 | 'Mali', 154 | 'Malta', 155 | 'Marshall Islands', 156 | 'Mauritania', 157 | 'Mauritius', 158 | 'Mexico', 159 | 'Micronesia', 160 | 'Moldova', 161 | 'Monaco', 162 | 'Mongolia', 163 | 'Morocco', 164 | 'Mozambique', 165 | 'Myanmar', 166 | 'Namibia', 167 | 'Nauru', 168 | 'Nepal', 169 | 'Netherlands', 170 | 'New Zealand', 171 | 'Nicaragua', 172 | 'Niger', 173 | 'Nigeria', 174 | 'Norway', 175 | 'Oman', 176 | 'Pakistan', 177 | 'Palau', 178 | 'Panama', 179 | 'Papua New Guinea', 180 | 'Paraguay', 181 | 'Peru', 182 | 'Philippines', 183 | 'Poland', 184 | 'Portugal', 185 | 'Qatar', 186 | 'Romania', 187 | 'Russia', 188 | 'Rwanda', 189 | 'Saint Kitts and Nevis', 190 | 'Saint Lucia', 191 | 'Saint Vincent', 192 | 'Samoa', 193 | 'San Marino', 194 | 'Sao Tome and Principe', 195 | 'Saudi Arabia', 196 | 'Senegal', 197 | 'Serbia and Montenegro', 198 | 'Seychelles', 199 | 'Sierra Leone', 200 | 'Singapore', 201 | 'Slovakia', 202 | 'Slovenia', 203 | 'Solomon Islands', 204 | 'Somalia', 205 | 'South Africa', 206 | 'Spain', 207 | 'Sri Lanka', 208 | 'Sudan', 209 | 'Suriname', 210 | 'Swaziland', 211 | 'Sweden', 212 | 'Switzerland', 213 | 'Syria', 214 | 'Taiwan', 215 | 'Tajikistan', 216 | 'Tanzania', 217 | 'Thailand', 218 | 'Togo', 219 | 'Tonga', 220 | 'Trinidad and Tobago', 221 | 'Tunisia', 222 | 'Turkey', 223 | 'Turkmenistan', 224 | 'Tuvalu', 225 | 'Uganda', 226 | 'Ukraine', 227 | 'United Arab Emirates', 228 | 'United Kingdom', 229 | 'United States', 230 | 'Uruguay', 231 | 'Uzbekistan', 232 | 'Vanuatu', 233 | 'Vatican City', 234 | 'Venezuela', 235 | 'Vietnam', 236 | 'Yemen', 237 | 'Zambia', 238 | 'Zimbabwe', 239 | ]; 240 | 241 | ''' for country in countries: 242 | if country.startswith('S'): 243 | pass 244 | # print(country) 245 | elif country.endswith('stan'): 246 | print(country) 247 | ''' 248 | 249 | countries_with_land = [] 250 | for c in countries: 251 | if 'land' in c: 252 | countries_with_land.append(c) 253 | 254 | print(countries_with_land) -------------------------------------------------------------------------------- /Week-4/functions.py: -------------------------------------------------------------------------------- 1 | ''' def print_fullname(): 2 | first_name = 'Asabeneh' 3 | last_name = 'Yetayeh' 4 | print(first_name, last_name) 5 | 6 | print_fullname() ''' 7 | 8 | 9 | ''' def print_fullname(first_name, last_name): 10 | print(first_name, last_name) 11 | 12 | print_fullname('John','Doe') 13 | print_fullname('Asab','Yeta') 14 | print_fullname('Alex','David') ''' 15 | 16 | 17 | 18 | def print_fullname(first_name, last_name): 19 | return first_name + ' ' + last_name 20 | 21 | 22 | print(print_fullname('John','Doe')) 23 | print(print_fullname('Asab','Yeta')) 24 | print(print_fullname('Alex','David')) 25 | 26 | 27 | def add_two_nums(a , b ): 28 | return a + b 29 | 30 | print(add_two_nums(1, 9)) 31 | print(add_two_nums(1, 99)) 32 | 33 | 34 | 35 | def make_square(n): 36 | return n ** 2 37 | 38 | print(make_square(3)) 39 | 40 | # calculate the weight of an object on different planets 41 | 42 | def calculate_weight(mass, gravity = 9.81): 43 | return mass * gravity 44 | 45 | print(calculate_weight(75)) 46 | print(calculate_weight(65)) 47 | print(round(calculate_weight(85, 1.62), 2)) -------------------------------------------------------------------------------- /Week-4/while-loop.py: -------------------------------------------------------------------------------- 1 | i = 0 2 | 3 | while i < 11: 4 | print(i) 5 | i = i + 1 6 | 7 | 8 | i = 10 9 | 10 | while i >= 0: 11 | print(i) 12 | i = i - 1 13 | -------------------------------------------------------------------------------- /Week-5/HOF.py: -------------------------------------------------------------------------------- 1 | # A function that returns other function 2 | # A function that takes other function as a parameter 3 | 4 | from cmath import sqrt 5 | from tkinter import N 6 | 7 | 8 | def do_math(n): 9 | def add_ten(): 10 | return n + 10 11 | return add_ten 12 | 13 | print(do_math(10)()) 14 | 15 | print(do_math(100)()) 16 | 17 | def make_square(n): 18 | return n ** 2 19 | 20 | def make_cube(f, n): 21 | return f(n) * n 22 | 23 | print(make_cube(make_square, 2)) 24 | print(make_cube(make_square, 3)) 25 | -------------------------------------------------------------------------------- /Week-5/dictionaries.py: -------------------------------------------------------------------------------- 1 | ''' 2 | empty_dct = {} 3 | print(type(empty_dct)) 4 | finnish_english_dct = { 5 | "talo":"house", 6 | "opiskelija":"student", 7 | "koulu":"school", 8 | "kirja":"book", 9 | "kirjasto":"library", 10 | "sana":'word', 11 | "sanasto":"dictionary" 12 | } 13 | print(finnish_english_dct) 14 | print(len(finnish_english_dct)) 15 | keys = finnish_english_dct.keys() 16 | print(keys) 17 | values = finnish_english_dct.values() 18 | print(values) 19 | items = finnish_english_dct.items() 20 | print(items) 21 | for item in items: 22 | print('The meaning of ', item[0],'is ', item[1]) ''' 23 | 24 | person = { 25 | 'first_name':'Asabeneh', 26 | 'last_name':'Yetayeh', 27 | 'country':'Finland', 28 | 'gender':'male', 29 | 'age':250, 30 | 'is_married':True, 31 | 'skills':['HTML','CSS','JS','TS','Python','Node'], 32 | 'address':{ 33 | 'city':'Espoo', 34 | 'zipcode':'02770', 35 | 'street_name':'space_street' 36 | } 37 | } 38 | print(person) 39 | print(person['first_name']) 40 | print(person['last_name']) 41 | 42 | if 'nationality' in person: 43 | print(person['nationality']) 44 | else: 45 | person['nationality'] = 'Ethipian' 46 | 47 | # We can use .get() method if we are not sure the key exists in the dictionary 48 | # Sometimes it is good to check if the key exist in the dictionary 49 | 50 | person['skills'].append('MYSQL') 51 | print(person) 52 | print(person['skills'][-3]) 53 | 54 | print(person) 55 | 56 | person['hobbies'] = ['Running', 'Ice Skating', 'Jogging'] 57 | person.pop('age') 58 | print(person) 59 | 60 | keys = person.keys() 61 | print(keys) 62 | values = person.values() 63 | print(values) 64 | items = person.items() 65 | print(items) 66 | person_copied = person.copy() 67 | person_copied['qualification'] = 'Software Engineer' 68 | print(person_copied) 69 | 70 | -------------------------------------------------------------------------------- /Week-5/exercises.py: -------------------------------------------------------------------------------- 1 | nums = [1, 2, 3, 9.81, 3.14] 2 | 3 | def sort_numbers_by_type(lst): 4 | integers = [] 5 | float_nums = [] 6 | for n in lst: 7 | if type(n) == int: 8 | integers.append(n) 9 | else: 10 | float_nums.append(n) 11 | # return intergers, float_nums 12 | return { 13 | 'floats':float_nums, 14 | 'integers':integers 15 | } 16 | 17 | print(sort_numbers_by_type(nums)) 18 | -------------------------------------------------------------------------------- /Week-5/functions.py: -------------------------------------------------------------------------------- 1 | def add_two_number(a, b): 2 | return a + b 3 | 4 | print(add_two_number(1, 2)) 5 | 6 | def make_square(n): 7 | return n ** 2 8 | 9 | print(make_square(5)) 10 | print(make_square(10)) 11 | print(make_square(-4)) 12 | countries = ['Finland','Sweden','Denmark','Iceland','Norway'] 13 | def change_list_item_to_uppercase(lst): 14 | new_lst = [] 15 | for item in lst: 16 | new_lst.append(item.upper()) 17 | return new_lst 18 | 19 | print(change_list_item_to_uppercase(countries)) 20 | print(change_list_item_to_uppercase(['Banana','Mango','Coffee','Milk'])) 21 | 22 | def sum_all_nums(n): 23 | total = 0 24 | for i in range(n+1): 25 | total = total + i 26 | return total 27 | 28 | print(sum_all_nums(3)) #6 29 | print(sum_all_nums(10)) # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 30 | print(sum_all_nums(1000)) -------------------------------------------------------------------------------- /Week-5/lambda_functions.py: -------------------------------------------------------------------------------- 1 | 2 | from operator import add 3 | 4 | 5 | make_square = lambda x: x ** 2 6 | 7 | print(make_square(10)) 8 | 9 | add_two_numbers = lambda a, b : a + b 10 | print(add_two_numbers(2, 3)) 11 | 12 | quardratic = lambda x, y: x ** 2 + y ** 2 + 2 * x * y 13 | print(quardratic(2, 2)) 14 | -------------------------------------------------------------------------------- /Week-5/list_dictionaries.py: -------------------------------------------------------------------------------- 1 | persons = [{ 2 | 'first_name':'Asabeneh', 3 | 'last_name':'Yetayeh', 4 | 'country':'Finland', 5 | 'gender':'male', 6 | 'age':250, 7 | 'is_married':True, 8 | 'skills':['HTML','CSS','JS','TS','Python','Node'], 9 | 'address':{ 10 | 'city':'Espoo', 11 | 'zipcode':'02770', 12 | 'street_name':'space_street' 13 | } 14 | }, 15 | { 16 | 'first_name':'John', 17 | 'last_name':'Doe', 18 | 'country':'Finland', 19 | 'gender':'male', 20 | 'age':25, 21 | 'is_married':True, 22 | 'skills':['HTML','CSS','JS','TS','Python','Node'], 23 | 'address':{ 24 | 'city':'Espoo', 25 | 'zipcode':'02770', 26 | 'street_name':'space_street' 27 | } 28 | }, 29 | { 30 | 'first_name':'Sami', 31 | 'last_name':'Antti', 32 | 'country':'Finland', 33 | 'gender':'male', 34 | 'age':28, 35 | 'is_married':True, 36 | 'skills':['HTML','CSS','JS','TS','Python','Node'], 37 | 'address':{ 38 | 'city':'Espoo', 39 | 'zipcode':'02770', 40 | 'street_name':'space_street' 41 | } 42 | }, 43 | { 44 | 'first_name':'Robert', 45 | 'last_name':'William', 46 | 'country':'Finland', 47 | 'gender':'male', 48 | 'age':18, 49 | 'is_married':True, 50 | 'skills':['HTML','CSS','JS','TS','Python','Node'], 51 | 'address':{ 52 | 'city':'Espoo', 53 | 'zipcode':'02770', 54 | 'street_name':'space_street' 55 | } 56 | } 57 | ] 58 | 59 | for person in persons: 60 | print(person['first_name']) -------------------------------------------------------------------------------- /Week-5/notes.md: -------------------------------------------------------------------------------- 1 | # Set, tuple, Dictionary 2 | # Functions, lambda function, higher order function 3 | # Functional programming 4 | 5 | cat api 6 | https://api.thecatapi.com/v1/breeds -------------------------------------------------------------------------------- /Week-5/sets.py: -------------------------------------------------------------------------------- 1 | empty_set = set() 2 | print(empty_set) 3 | print(len(empty_set)) 4 | 5 | fruits = {'banana','banana', 'orange', 'mango', 'lemon'} 6 | print(fruits) 7 | print(len(fruits)) 8 | fruits.add('avocado') 9 | print(fruits) 10 | 11 | for fruit in fruits: 12 | print(fruit) 13 | 14 | print('lemon' in fruits) 15 | print('apple' in fruits ) 16 | if 'apple' not in fruits: 17 | fruits.add('apple') 18 | 19 | print(fruits) 20 | 21 | ''' fruits.remove('banana') 22 | print(fruits) 23 | fruits.remove('mango') 24 | print(fruits) 25 | fruits.clear() 26 | 27 | print(len(fruits)) 28 | del fruits 29 | print(fruits) ''' 30 | 31 | fruits_lst = list(fruits) 32 | print(fruits_lst) 33 | 34 | A = {1, 2, 3, 4, 5, 6} 35 | B = {4, 5, 6, 7, 8, 9} 36 | # AUB = {1, 2, 3, 4, 5, 6, 7, 8, 9} 37 | # AnB = {4, 5, 6} 38 | # A\B = {1, 2, 3} 39 | # B\A = {7, 8, 9} 40 | # (AUB)\(AnB) = {1, 2, 3, 7, 8, 9} 41 | print(A.union(B)) 42 | print(B.union(A)) 43 | print(A.intersection(B)) 44 | print(B.intersection(A)) 45 | print(A.difference(B)) 46 | print(B.difference(A)) 47 | print(A.symmetric_difference(B)) 48 | print(A.isdisjoint(B)) 49 | print(A.issubset(B)) 50 | 51 | sentence = 'I love Python. It is the best programming language. But JavaScript is more important than any other programming languages. Do you agree?' 52 | word_lst = sentence.lower().replace('.', '').replace('?', '').split() 53 | print(len(word_lst), word_lst) 54 | words_st = set(word_lst) 55 | print(len(words_st), words_st) -------------------------------------------------------------------------------- /Week-5/tuple.py: -------------------------------------------------------------------------------- 1 | empty_tpl = tuple() 2 | print(empty_tpl) 3 | print(len(empty_tpl)) 4 | 5 | country_data = ('Finland', 'Helsinki', 'White and Blue', ) 6 | print(country_data[0]) 7 | print(country_data[-1]) 8 | 9 | for item in country_data: 10 | print(item) 11 | 12 | print('Espoo' in country_data) 13 | 14 | print(country_data.index('Helsinki')) 15 | 16 | tpl1 = (1, 2, 3) 17 | tpl2 = (4, 5, 6) 18 | tpl3 = tpl1 + tpl2 19 | print(tpl3) 20 | 21 | lst1 = [1, 2, 3] 22 | lst2 = [4, 5, 6] 23 | lst3 = lst1 + lst2 24 | print(lst3) 25 | 26 | del country_data 27 | 28 | print(country_data) --------------------------------------------------------------------------------