From f65a3af42dfbcbf09336e9089a105183163e8723 Mon Sep 17 00:00:00 2001 From: Aren <95090911+rawbytedev@users.noreply.github.com> Date: Tue, 31 Dec 2024 22:48:40 +0100 Subject: [PATCH 1/2] upload fixes and changes Resolved errors(need some reviewing, might have missed some errors) Added comments Changed print to return (to avoid None) Removed <\div> Reviewed exercises and numbered them Removed ";" in some part (; doesn't trigger error) Reviewed the python files --- .../02_variables_builtin_functions.md | 26 ++++++------ .../variables.py | 3 +- 03_Day_Operators/03_operators.md | 4 +- 04_Day_Strings/04_strings.md | 14 +++---- 04_Day_Strings/day_4.py | 14 +++---- 05_Day_Lists/05_lists.md | 4 +- 05_Day_Lists/day_5.py | 2 +- 06_Day_Tuples/06_tuples.md | 4 +- 07_Day_Sets/07_sets.md | 16 ++++---- 08_Day_Dictionaries/08_dictionaries.md | 2 +- 09_Day_Conditionals/09_conditionals.md | 4 +- 10_Day_Loops/10_loops.md | 6 +-- 11_Day_Functions/11_functions.md | 25 ++++++------ 12_Day_Modules/12_modules.md | 10 ++--- 12_Day_Modules/main.py | 3 +- .../13_list_comprehension.md | 2 +- .../14_higher_order_functions.md | 7 ++-- .../15_python_type_errors.md | 2 +- 16_Day_Python_date_time/16_python_datetime.md | 11 +++-- .../18_regular_expressions.md | 12 +++--- 19_Day_File_handling/19_file_handling.md | 40 +++++++++---------- .../21_classes_and_objects.md | 7 +--- readme.md | 2 +- 23 files changed, 107 insertions(+), 113 deletions(-) diff --git a/02_Day_Variables_builtin_functions/02_variables_builtin_functions.md b/02_Day_Variables_builtin_functions/02_variables_builtin_functions.md index 400b990c..3f94e95c 100644 --- a/02_Day_Variables_builtin_functions/02_variables_builtin_functions.md +++ b/02_Day_Variables_builtin_functions/02_variables_builtin_functions.md @@ -280,22 +280,22 @@ Number data types in Python: ### Exercises: Level 2 1. Check the data type of all your variables using type() built-in function -1. Using the _len()_ built-in function, find the length of your first name -1. Compare the length of your first name and your last name -1. Declare 5 as num_one and 4 as num_two -1. Add num_one and num_two and assign the value to a variable total -1. Subtract num_two from num_one and assign the value to a variable diff -1. Multiply num_two and num_one and assign the value to a variable product -1. Divide num_one by num_two and assign the value to a variable division -1. Use modulus division to find num_two divided by num_one and assign the value to a variable remainder -1. Calculate num_one to the power of num_two and assign the value to a variable exp -1. Find floor division of num_one by num_two and assign the value to a variable floor_division -1. The radius of a circle is 30 meters. +2. Using the _len()_ built-in function, find the length of your first name +3. Compare the length of your first name and your last name +4. Declare 5 as num_one and 4 as num_two +5. Add num_one and num_two and assign the value to a variable total +6. Subtract num_two from num_one and assign the value to a variable diff +7. Multiply num_two and num_one and assign the value to a variable product +8. Divide num_one by num_two and assign the value to a variable division +9. Use modulus division to find num_two divided by num_one and assign the value to a variable remainder +10. Calculate num_one to the power of num_two and assign the value to a variable exp +11. Find floor division of num_one by num_two and assign the value to a variable floor_division +12. The radius of a circle is 30 meters. 1. Calculate the area of a circle and assign the value to a variable name of _area_of_circle_ 2. Calculate the circumference of a circle and assign the value to a variable name of _circum_of_circle_ 3. Take radius as user input and calculate the area. -1. Use the built-in input function to get first name, last name, country and age from a user and store the value to their corresponding variable names -1. Run help('keywords') in Python shell or in your file to check for the Python reserved words or keywords +13. Use the built-in input function to get first name, last name, country and age from a user and store the value to their corresponding variable names +14. Run help('keywords') in Python shell or in your file to check for the Python reserved words or keywords πŸŽ‰ CONGRATULATIONS ! πŸŽ‰ diff --git a/02_Day_Variables_builtin_functions/variables.py b/02_Day_Variables_builtin_functions/variables.py index 78ba0e71..c4c66749 100644 --- a/02_Day_Variables_builtin_functions/variables.py +++ b/02_Day_Variables_builtin_functions/variables.py @@ -37,4 +37,5 @@ print('Last name: ', last_name) print('Country: ', country) print('Age: ', age) -print('Married: ', is_married) \ No newline at end of file +print('Married: ', is_married) + diff --git a/03_Day_Operators/03_operators.md b/03_Day_Operators/03_operators.md index 0fcfeb99..26ad7b89 100644 --- a/03_Day_Operators/03_operators.md +++ b/03_Day_Operators/03_operators.md @@ -121,7 +121,7 @@ print('a * b = ', product) print('a / b = ', division) print('a % b = ', remainder) print('a // b = ', floor_division) -print('a ** b = ', exponentiation) +print('a ** b = ', exponential) ``` **Example:** @@ -174,7 +174,7 @@ print(weight, 'N') # Adding unit to the weight mass = 75 # in Kg volume = 0.075 # in cubic meter density = mass / volume # 1000 Kg/m^3 - +print(density) ``` ### Comparison Operators diff --git a/04_Day_Strings/04_strings.md b/04_Day_Strings/04_strings.md index 3bf09ed2..fc3ddd71 100644 --- a/04_Day_Strings/04_strings.md +++ b/04_Day_Strings/04_strings.md @@ -92,7 +92,7 @@ print(len(full_name)) # 16 In Python and other programming languages \ followed by a character is an escape sequence. Let us see the most common escape characters: - \n: new line -- \t: Tab means(8 spaces) +- \t: Tab means(8 spaces) - \\\\: Back slash - \\': Single quote (') - \\": Double quote (") @@ -101,7 +101,7 @@ Now, let us see the use of the above escape sequences with examples. ```py print('I hope everyone is enjoying the Python Challenge.\nAre you ?') # line break -print('Days\tTopics\tExercises') # adding tab space or 4 spaces +print('Days\tTopics\tExercises') # adding tab space or 4 spaces print('Day 1\t5\t5') print('Day 2\t6\t20') print('Day 3\t5\t23') @@ -112,7 +112,7 @@ print('In every programming language it starts with \"Hello, World!\"') # to wri # output I hope every one is enjoying the Python Challenge. Are you ? -Days Topics Exercises +Days Topics Exercises Day 1 5 5 Day 2 6 20 Day 3 5 23 @@ -349,7 +349,7 @@ last_name = 'Yetayeh' age = 250 job = 'teacher' country = 'Finland' -sentence = 'I am {} {}. I am a {}. I am {} years old. I live in {}.'.format(first_name, last_name, age, job, country) +sentence = 'I am {} {}. I am {} years old. I am a {}. I live in {}.'.format(first_name, last_name, age, job, country) print(sentence) # I am Asabeneh Yetayeh. I am 250 years old. I am a teacher. I live in Finland. radius = 10 @@ -413,7 +413,7 @@ print(challenge.isdecimal()) # False challenge = '123' print(challenge.isdecimal()) # True challenge = '\u00B2' -print(challenge.isdigit()) # False +print(challenge.isdigit()) # True challenge = '12 3' print(challenge.isdecimal()) # False, space not allowed ``` @@ -545,7 +545,7 @@ print(challenge.startswith('thirty')) # False 9. Cut(slice) out the first word of _Coding For All_ string. 10. Check if _Coding For All_ string contains a word Coding using the method index, find or other methods. 11. Replace the word coding in the string 'Coding For All' to Python. -12. Change Python for Everyone to Python for All using the replace method or other methods. +12. Change "Python for Everyone" to "Python for All" using the replace method or other methods. 13. Split the string 'Coding For All' using space as the separator (split()) . 14. "Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon" split the string at the comma. 15. What is the character at index 0 in the string _Coding For All_. @@ -561,7 +561,7 @@ print(challenge.startswith('thirty')) # False 25. Slice out the phrase 'because because because' in the following sentence: 'You cannot end a sentence with because because because is a conjunction' 26. Find the position of the first occurrence of the word 'because' in the following sentence: 'You cannot end a sentence with because because because is a conjunction' 27. Slice out the phrase 'because because because' in the following sentence: 'You cannot end a sentence with because because because is a conjunction' -28. Does '\'Coding For All' start with a substring _Coding_? +28. Does 'Coding For All' start with a substring _Coding_? 29. Does 'Coding For All' end with a substring _coding_? 30. '   Coding For All      '  , remove the left and right trailing spaces in the given string. 31. Which one of the following variables return True when we use the method isidentifier(): diff --git a/04_Day_Strings/day_4.py b/04_Day_Strings/day_4.py index 28ddc262..b196c9b1 100644 --- a/04_Day_Strings/day_4.py +++ b/04_Day_Strings/day_4.py @@ -30,7 +30,7 @@ print(len(first_name)) # 8 print(len(last_name)) # 7 print(len(first_name) > len(last_name)) # True -print(len(full_name)) # 15 +print(len(full_name)) # 16 #### Unpacking characters language = 'Python' @@ -152,8 +152,8 @@ # isalpha(): Checks if all characters are alphabets -challenge = 'thirty days of python' -print(challenge.isalpha()) # True +challenge = 'thirty days of python' # space is not in alphabet +print(challenge.isalpha()) # False num = '123' print(num.isalpha()) # False @@ -168,7 +168,7 @@ challenge = 'Thirty' print(challenge.isdigit()) # False challenge = '30' -print(challenge.digit()) # True +print(challenge.isdigit()) # True # isdecimal():Checks decimal characters @@ -210,13 +210,13 @@ # join(): Returns a concatenated string web_tech = ['HTML', 'CSS', 'JavaScript', 'React'] -result = '#, '.join(web_tech) -print(result) # 'HTML# CSS# JavaScript# React' +result = '# '.join(web_tech) +print(result) # 'HTML# CSS# JavaScript# React' # strip(): Removes both leading and trailing characters challenge = ' thirty days of python ' -print(challenge.strip('y')) # 5 +print(challenge.strip()) # 'thirty days of python' # replace(): Replaces substring inside diff --git a/05_Day_Lists/05_lists.md b/05_Day_Lists/05_lists.md index 19a1a704..df3cf38e 100644 --- a/05_Day_Lists/05_lists.md +++ b/05_Day_Lists/05_lists.md @@ -91,7 +91,7 @@ fruits = ['banana', 'orange', 'mango', 'lemon'] # list of fr vegetables = ['Tomato', 'Potato', 'Cabbage','Onion', 'Carrot'] # list of vegetables animal_products = ['milk', 'meat', 'butter', 'yoghurt'] # list of animal products web_techs = ['HTML', 'CSS', 'JS', 'React','Redux', 'Node', 'MongDB'] # list of web technologies -countries = ['Finland', 'Estonia', 'Denmark', 'Sweden', 'Norway'] +countries = ['Finland', 'Estonia', 'Denmark', 'Sweden', 'Norway'] # Print the lists and its length print('Fruits:', fruits) @@ -190,7 +190,7 @@ print(tenth) # 10 # Third Example about unpacking list countries = ['Germany', 'France','Belgium','Sweden','Denmark','Finland','Norway','Iceland','Estonia'] gr, fr, bg, sw, *scandic, es = countries -print(gr) +print(gr) print(fr) print(bg) print(sw) diff --git a/05_Day_Lists/day_5.py b/05_Day_Lists/day_5.py index 9e7e1546..2959f999 100644 --- a/05_Day_Lists/day_5.py +++ b/05_Day_Lists/day_5.py @@ -106,7 +106,7 @@ del fruits[1] print(fruits) # ['orange', 'lemon'] del fruits -print(fruits) # This should give: NameError: name 'fruits' is not defined +#print(fruits) # This should give: NameError: name 'fruits' is not defined # clear fruits = ['banana', 'orange', 'mango', 'lemon'] diff --git a/06_Day_Tuples/06_tuples.md b/06_Day_Tuples/06_tuples.md index 8823d231..85a0984d 100644 --- a/06_Day_Tuples/06_tuples.md +++ b/06_Day_Tuples/06_tuples.md @@ -79,7 +79,7 @@ len(tpl) - Positive Indexing Similar to the list data type we use positive or negative indexing to access tuple items. - ![Accessing tuple items](../images/tuples_index.png) + ![Accessing tuple items](../images/tuples_incdex.png) ```py # Syntax @@ -93,7 +93,7 @@ len(tpl) first_fruit = fruits[0] second_fruit = fruits[1] last_index =len(fruits) - 1 - last_fruit = fruits[las_index] + last_fruit = fruits[last_index] ``` - Negative indexing diff --git a/07_Day_Sets/07_sets.md b/07_Day_Sets/07_sets.md index 3c61dd07..5fdbca6b 100644 --- a/07_Day_Sets/07_sets.md +++ b/07_Day_Sets/07_sets.md @@ -411,18 +411,18 @@ age = [22, 19, 24, 25, 26, 24, 25, 24] ### Exercises: Level 2 1. Join A and B -1. Find A intersection B -1. Is A subset of B -1. Are A and B disjoint sets -1. Join A with B and B with A -1. What is the symmetric difference between A and B -1. Delete the sets completely +2. Find A intersection B +3. Is A subset of B +4. Are A and B disjoint sets +5. Join A with B and B with A +6. What is the symmetric difference between A and B +7. Delete the sets completely ### Exercises: Level 3 1. Convert the ages to a set and compare the length of the list and the set, which one is bigger? -1. Explain the difference between the following data types: string, list, tuple and set -2. _I am a teacher and I love to inspire and teach people._ How many unique words have been used in the sentence? Use the split methods and set to get the unique words. +2. Explain the difference between the following data types: string, list, tuple and set +3. _I am a teacher and I love to inspire and teach people._ How many unique words have been used in the sentence? Use the split methods and set to get the unique words. πŸŽ‰ CONGRATULATIONS ! πŸŽ‰ diff --git a/08_Day_Dictionaries/08_dictionaries.md b/08_Day_Dictionaries/08_dictionaries.md index 8d6bc2c4..07bd049e 100644 --- a/08_Day_Dictionaries/08_dictionaries.md +++ b/08_Day_Dictionaries/08_dictionaries.md @@ -150,7 +150,7 @@ person = { } print(person.get('first_name')) # Asabeneh print(person.get('country')) # Finland -print(person.get('skills')) #['HTML','CSS','JavaScript', 'React', 'Node', 'MongoDB', 'Python'] +print(person.get('skills')) #['JavaScript', 'React', 'Node', 'MongoDB', 'Python'] print(person.get('city')) # None ``` diff --git a/09_Day_Conditionals/09_conditionals.md b/09_Day_Conditionals/09_conditionals.md index 522bbac3..ee9d3795 100644 --- a/09_Day_Conditionals/09_conditionals.md +++ b/09_Day_Conditionals/09_conditionals.md @@ -241,12 +241,12 @@ Enter number two: 3 0-49, F ``` - 1. Check if the season is Autumn, Winter, Spring or Summer. If the user input is: + 2. Get the month from user input then check if the season is Autumn, Winter, Spring or Summer. If the user input is: September, October or November, the season is Autumn. December, January or February, the season is Winter. March, April or May, the season is Spring June, July or August, the season is Summer - 2. The following list contains some fruits: + 3. The following list contains some fruits: ```sh fruits = ['banana', 'orange', 'mango', 'lemon'] diff --git a/10_Day_Loops/10_loops.md b/10_Day_Loops/10_loops.md index f03265a9..a80ac169 100644 --- a/10_Day_Loops/10_loops.md +++ b/10_Day_Loops/10_loops.md @@ -441,7 +441,7 @@ for number in range(6): The sum of all numbers is 5050. ``` -1. Use for loop to iterate from 0 to 100 and print the sum of all evens and the sum of all odds. +2. Use for loop to iterate from 0 to 100 and print the sum of all evens and the sum of all odds. ```sh The sum of all evens is 2550. And the sum of all odds is 2500. @@ -450,8 +450,8 @@ for number in range(6): ### Exercises: Level 3 1. Go to the data folder and use the [countries.py](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/countries.py) file. Loop through the countries and extract all the countries containing the word _land_. -1. This is a fruit list, ['banana', 'orange', 'mango', 'lemon'] reverse the order using loop. -2. Go to the data folder and use the [countries_data.py](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/countries-data.py) file. +2. This is a fruit list, ['banana', 'orange', 'mango', 'lemon'] reverse the order using loop. +3. Go to the data folder and use the [countries_data.py](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/countries-data.py) file. 1. What are the total number of languages in the data 2. Find the ten most spoken languages from the data 3. Find the 10 most populated countries in the world diff --git a/11_Day_Functions/11_functions.md b/11_Day_Functions/11_functions.md index 2a0ad39b..40d402d6 100644 --- a/11_Day_Functions/11_functions.md +++ b/11_Day_Functions/11_functions.md @@ -149,7 +149,7 @@ def sum_of_numbers(n): total = 0 for i in range(n+1): total+=i - print(total) + return total print(sum_of_numbers(10)) # 55 print(sum_of_numbers(100)) # 5050 ``` @@ -182,7 +182,7 @@ print('Sum of two numbers: ', sum_two_numbers(1, 9)) def calculate_age (current_year, birth_year): age = current_year - birth_year - return age; + return age print('Age: ', calculate_age(2021, 1819)) @@ -213,12 +213,12 @@ def print_fullname(firstname, lastname): space = ' ' full_name = firstname + space + lastname print(full_name) -print(print_fullname(firstname = 'Asabeneh', lastname = 'Yetayeh')) +print_fullname(firstname = 'Asabeneh', lastname = 'Yetayeh') def add_two_numbers (num1, num2): total = num1 + num2 - print(total) -print(add_two_numbers(num2 = 3, num1 = 2)) # Order does not matter + return total +print(add_two_numbers(num2 = 3, num1 = 2)) # Order does not matter ``` ### Function Returning a Value - Part 2 @@ -252,7 +252,7 @@ print(add_two_numbers(2, 3)) def calculate_age (current_year, birth_year): age = current_year - birth_year - return age; + return age print('Age: ', calculate_age(2019, 1819)) ``` @@ -262,7 +262,6 @@ print('Age: ', calculate_age(2019, 1819)) ```py def is_even (n): if n % 2 == 0: - print('even') return True # return stops further execution of the function, similar to break return False print(is_even(10)) # True @@ -316,7 +315,7 @@ print(generate_full_name('David','Smith')) def calculate_age (birth_year,current_year = 2021): age = current_year - birth_year - return age; + return age print('Age: ', calculate_age(1821)) def weight_of_object (mass, gravity = 9.81): @@ -357,8 +356,8 @@ print(sum_all_nums(2, 3, 5)) # 10 def generate_groups (team,*args): print(team) for i in args: - print(i) -print(generate_groups('Team-1','Asabeneh','Brook','David','Eyob')) + print(i) +generate_groups('Team-1','Asabeneh','Brook','David','Eyob') ``` ### Function as a Parameter of Another Function @@ -369,7 +368,7 @@ def square_number (n): return n * n def do_something(f, x): return f(x) -print(do_something(square_number, 3)) # 27 +print(do_something(square_number, 3)) # 9 ``` πŸŒ• You achieved quite a lot so far. Keep going! You have just completed day 11 challenges and you are 11 steps a head in to your way to greatness. Now do some exercises for your brain and muscles. @@ -395,7 +394,7 @@ Now it is time to express your thoughts about the Author and 30DaysOfPython. You ```py print(reverse_list([1, 2, 3, 4, 5])) # [5, 4, 3, 2, 1] -print(reverse_list1(["A", "B", "C"])) +print(reverse_list(["A", "B", "C"])) # ["C", "B", "A"] ``` @@ -406,7 +405,7 @@ print(reverse_list1(["A", "B", "C"])) food_staff = ['Potato', 'Tomato', 'Mango', 'Milk'] print(add_item(food_staff, 'Meat')) # ['Potato', 'Tomato', 'Mango', 'Milk','Meat'] numbers = [2, 3, 7, 9] -print(add_item(numbers, 5)) [2, 3, 7, 9, 5] +print(add_item(numbers, 5)) # [2, 3, 7, 9, 5] ``` 12. Declare a function named remove_item. It takes a list and an item parameters. It returns a list with the item removed from it. diff --git a/12_Day_Modules/12_modules.md b/12_Day_Modules/12_modules.md index caa6e94b..07508a88 100644 --- a/12_Day_Modules/12_modules.md +++ b/12_Day_Modules/12_modules.md @@ -12,7 +12,7 @@ Second Edition: July, 2021 - + [<< Day 11](../11_Day_Functions/11_functions.md) | [Day 13>>](../13_Day_List_comprehension/13_list_comprehension.md) @@ -77,7 +77,7 @@ We can have many functions in a file and we can import all the functions differe from mymodule import generate_full_name, sum_two_nums, person, gravity print(generate_full_name('Asabneh','Yetayeh')) print(sum_two_nums(1,9)) -mass = 100; +mass = 100 weight = mass * gravity print(weight) print(person['firstname']) @@ -92,7 +92,7 @@ During importing we can rename the name of the module. from mymodule import generate_full_name as fullname, sum_two_nums as total, person as p, gravity as g print(fullname('Asabneh','Yetayeh')) print(total(1, 9)) -mass = 100; +mass = 100 weight = mass * g print(weight) print(p) @@ -251,9 +251,9 @@ print(randint(5, 20)) # it returns a random integer number between [5, 20] inclu ### Exercises: Level 1 -1. Writ a function which generates a six digit/character random_user_id. +1. Write a function which generates a six digit/character random_user_id. ```py - print(random_user_id()); + print(random_user_id()) '1ee33d' ``` 2. Modify the previous task. Declare a function named user_id_gen_by_user. It doesn’t take any parameters but it takes two inputs using input(). One of the inputs is the number of characters and the second input is the number of IDs which are supposed to be generated. diff --git a/12_Day_Modules/main.py b/12_Day_Modules/main.py index 2c11370d..e5e3e416 100644 --- a/12_Day_Modules/main.py +++ b/12_Day_Modules/main.py @@ -2,7 +2,8 @@ from mymodule import generate_full_name as fullname, sum_two_nums as total, person as p, gravity as g print(fullname('Asabneh','Yetayeh')) print(total(1, 9)) -mass = 100; +mass = 100 +print(mass) weight = mass * g print(weight) print(p) diff --git a/13_Day_List_comprehension/13_list_comprehension.md b/13_Day_List_comprehension/13_list_comprehension.md index a2cd9aa9..8b5f2ea3 100644 --- a/13_Day_List_comprehension/13_list_comprehension.md +++ b/13_Day_List_comprehension/13_list_comprehension.md @@ -12,7 +12,7 @@ Second Edition: July, 2021 - + [<< Day 12](../12_Day_Modules/12_modules.md) | [Day 14>>](../14_Day_Higher_order_functions/14_higher_order_functions.md) diff --git a/14_Day_Higher_order_functions/14_higher_order_functions.md b/14_Day_Higher_order_functions/14_higher_order_functions.md index 2af24c65..e4a75950 100644 --- a/14_Day_Higher_order_functions/14_higher_order_functions.md +++ b/14_Day_Higher_order_functions/14_higher_order_functions.md @@ -11,8 +11,8 @@ Asabeneh Yetayeh
Second Edition: July, 2021 - - + + [<< Day 13](../13_Day_List_comprehension/13_list_comprehension.md) | [Day 15>>](../15_Day_Python_type_errors/15_python_type_errors.md) @@ -177,14 +177,13 @@ def split_string_decorator(function): func = function() splitted_string = func.split() return splitted_string - return wrapper @split_string_decorator @uppercase_decorator # order with decorators is important in this case - .upper() function does not work with lists def greeting(): return 'Welcome to Python' -print(greeting()) # WELCOME TO PYTHON +print(greeting()) # ['WELCOME', 'TO', 'PYTHON'] ``` ### Accepting Parameters in Decorator Functions diff --git a/15_Day_Python_type_errors/15_python_type_errors.md b/15_Day_Python_type_errors/15_python_type_errors.md index 16c3e713..e9c90b73 100644 --- a/15_Day_Python_type_errors/15_python_type_errors.md +++ b/15_Day_Python_type_errors/15_python_type_errors.md @@ -11,7 +11,7 @@ Asabeneh Yetayeh
Second Edition: July, 2021 - + [<< Day 14](../14_Day_Higher_order_functions/14_higher_order_functions.md) | [Day 16 >>](../16_Day_Python_date_time/16_python_datetime.md) diff --git a/16_Day_Python_date_time/16_python_datetime.md b/16_Day_Python_date_time/16_python_datetime.md index e103a599..b4cbc56d 100644 --- a/16_Day_Python_date_time/16_python_datetime.md +++ b/16_Day_Python_date_time/16_python_datetime.md @@ -11,7 +11,6 @@ Asabeneh Yetayeh
Second Edition: July, 2021 - [<< Day 15](../15_Day_Python_type_errors/15_python_type_errors.md) | [Day 17 >>](../17_Day_Exception_handling/17_exception_handling.md) @@ -194,11 +193,11 @@ print("t3 =", t3) ## πŸ’» Exercises: Day 16 1. Get the current day, month, year, hour, minute and timestamp from datetime module -1. Format the current date using this format: "%m/%d/%Y, %H:%M:%S") -1. Today is 5 December, 2019. Change this time string to time. -1. Calculate the time difference between now and new year. -1. Calculate the time difference between 1 January 1970 and now. -1. Think, what can you use the datetime module for? Examples: +2. Format the current date using this format: "%m/%d/%Y, %H:%M:%S") +3. Today is 5 December, 2019. Change this time string to time. +4. Calculate the time difference between now and new year. +5. Calculate the time difference between 1 January 1970 and now. +6. Think, what can you use the datetime module for? Examples: - Time series analysis - To get a timestamp of any activities in an application - Adding posts on a blog diff --git a/18_Day_Regular_expressions/18_regular_expressions.md b/18_Day_Regular_expressions/18_regular_expressions.md index 4492c91b..6b78da70 100644 --- a/18_Day_Regular_expressions/18_regular_expressions.md +++ b/18_Day_Regular_expressions/18_regular_expressions.md @@ -12,7 +12,7 @@ First Edition: Nov 22 - Dec 22, 2019 - + [<< Day 17](../17_Day_Exception_handling/17_exception_handling.md) | [Day 19>>](../19_Day_File_handling/19_file_handling.md) @@ -85,7 +85,7 @@ span = match.span() print(span) # (0, 15) # Lets find the start and stop position from the span start, end = span -print(start, end) # 0, 15 +print(start, end) # 0 15 substring = txt[start:end] print(substring) # I love to teach ``` @@ -179,10 +179,10 @@ txt = '''Python is the most beautiful language that a human being has ever creat I recommend python for a first programming language''' match_replaced = re.sub('Python|python', 'JavaScript', txt, re.I) -print(match_replaced) # JavaScript is the most beautiful language that a human being has ever created. +print(match_replaced) # JavaScript is the most beautiful language that a human being has ever created.I recommend python for a first programming language # OR match_replaced = re.sub('[Pp]ython', 'JavaScript', txt, re.I) -print(match_replaced) # JavaScript is the most beautiful language that a human being has ever created. +print(match_replaced) # JavaScript is the most beautiful language that a human being has ever created.I recommend python for a first programming language ``` Let us add one more example. The following string is really hard to read unless we remove the % symbol. Replacing the % with an empty string will clean the text. @@ -361,9 +361,9 @@ matches = re.findall(regex_pattern, txt) print(matches) # ['2019', '2021'] txt = 'This regular expression example was made on December 6, 2019 and revised on July 8, 2021' -regex_pattern = r'\d{1, 4}' # 1 to 4 +regex_pattern = r'\d{1,4}' matches = re.findall(regex_pattern, txt) -print(matches) # ['6', '2019', '8', '2021'] +print(matches) # ['6', '2019', '8', '2021'] ``` ### Cart ^ diff --git a/19_Day_File_handling/19_file_handling.md b/19_Day_File_handling/19_file_handling.md index de51b9bd..18ab20a4 100644 --- a/19_Day_File_handling/19_file_handling.md +++ b/19_Day_File_handling/19_file_handling.md @@ -333,7 +333,7 @@ CSV stands for comma separated values. CSV is a simple file format used to store ```py import csv with open('./files/csv_example.csv') as f: - csv_reader = csv.reader(f, delimiter=',') # w use, reader method to read csv + csv_reader = csv.reader(f, delimiter=',') # we use, reader method to read csv line_count = 0 for row in csv_reader: if line_count == 0: @@ -359,7 +359,7 @@ To read excel files we need to install _xlrd_ package. We will cover this after ```py import xlrd -excel_book = xlrd.open_workbook('sample.xls) +excel_book = xlrd.open_workbook('sample.xls') print(excel_book.nsheets) print(excel_book.sheet_names) ``` @@ -412,10 +412,10 @@ field: skills ### Exercises: Level 1 1. Write a function which count number of lines and number of words in a text. All the files are in the data the folder: - a) Read obama_speech.txt file and count number of lines and words - b) Read michelle_obama_speech.txt file and count number of lines and words - c) Read donald_speech.txt file and count number of lines and words - d) Read melina_trump_speech.txt file and count number of lines and words + 1) Read obama_speech.txt file and count number of lines and words + 2) Read michelle_obama_speech.txt file and count number of lines and words + 3) Read donald_speech.txt file and count number of lines and words + 4) Read melina_trump_speech.txt file and count number of lines and words 2. Read the countries_data.json data file in data directory, create a function that finds the ten most spoken languages ```py @@ -471,8 +471,8 @@ field: skills ### Exercises: Level 2 -4. Extract all incoming email addresses as a list from the email_exchange_big.txt file. -5. Find the most common words in the English language. Call the name of your function find_most_common_words, it will take two parameters - a string or a file and a positive integer, indicating the number of words. Your function will return an array of tuples in descending order. Check the output +1. Extract all incoming email addresses as a list from the email_exchange_big.txt file. +2. Find the most common words in the English language. Call the name of your function find_most_common_words, it will take two parameters - a string or a file and a positive integer, indicating the number of words. Your function will return an array of tuples in descending order. Check the output ```py # Your output should look like this @@ -498,19 +498,17 @@ field: skills (5, 'and')] ``` -6. Use the function, find_most_frequent_words to find: - a) The ten most frequent words used in [Obama's speech](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/obama_speech.txt) - b) The ten most frequent words used in [Michelle's speech](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/michelle_obama_speech.txt) - c) The ten most frequent words used in [Trump's speech](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/donald_speech.txt) - d) The ten most frequent words used in [Melina's speech](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/melina_trump_speech.txt) -7. Write a python application that checks similarity between two texts. It takes a file or a string as a parameter and it will evaluate the similarity of the two texts. For instance check the similarity between the transcripts of [Michelle's](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/michelle_obama_speech.txt) and [Melina's](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/melina_trump_speech.txt) speech. You may need a couple of functions, function to clean the text(clean_text), function to remove support words(remove_support_words) and finally to check the similarity(check_text_similarity). List of [stop words](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/stop_words.py) are in the data directory -8. Find the 10 most repeated words in the romeo_and_juliet.txt -9. Read the [hacker news csv](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/hacker_news.csv) file and find out: - a) Count the number of lines containing python or Python - b) Count the number lines containing JavaScript, javascript or Javascript - c) Count the number lines containing Java and not JavaScript - -### Exercises: Level 3 +3. Use the function, find_most_frequent_words to find: + 1) The ten most frequent words used in [Obama's speech](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/obama_speech.txt) + 2) The ten most frequent words used in [Michelle's speech](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/michelle_obama_speech.txt) + 3) The ten most frequent words used in [Trump's speech](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/donald_speech.txt) + 4) The ten most frequent words used in [Melina's speech](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/melina_trump_speech.txt) +4. Write a python application that checks similarity between two texts. It takes a file or a string as a parameter and it will evaluate the similarity of the two texts. For instance check the similarity between the transcripts of [Michelle's](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/michelle_obama_speech.txt) and [Melina's](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/melina_trump_speech.txt) speech. You may need a couple of functions, function to clean the text(clean_text), function to remove support words(remove_support_words) and finally to check the similarity(check_text_similarity). List of [stop words](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/stop_words.py) are in the data directory +5. Find the 10 most repeated words in the romeo_and_juliet.txt +6. Read the [hacker news csv](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/hacker_news.csv) file and find out: + 1) Count the number of lines containing python or Python + 2) Count the number lines containing JavaScript, javascript or Javascript + 3) Count the number lines containing Java and not JavaScript πŸŽ‰ CONGRATULATIONS ! πŸŽ‰ diff --git a/21_Day_Classes_and_objects/21_classes_and_objects.md b/21_Day_Classes_and_objects/21_classes_and_objects.md index 9876cfb5..66455655 100644 --- a/21_Day_Classes_and_objects/21_classes_and_objects.md +++ b/21_Day_Classes_and_objects/21_classes_and_objects.md @@ -333,7 +333,7 @@ print('Count:', data.count()) # 25 print('Sum: ', data.sum()) # 744 print('Min: ', data.min()) # 24 print('Max: ', data.max()) # 38 -print('Range: ', data.range() # 14 +print('Range: ', data.range()) # 14 print('Mean: ', data.mean()) # 30 print('Median: ', data.median()) # 29 print('Mode: ', data.mode()) # {'mode': 26, 'count': 5} @@ -360,10 +360,7 @@ Frequency Distribution: [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34 ### Exercises: Level 2 -1. Create a class called PersonAccount. It has firstname, lastname, incomes, expenses properties and it has total_income, total_expense, account_info, add_income, add_expense and account_balance methods. Incomes is a set of incomes and its description. The same goes for expenses. - -### Exercises: Level 3 - +1. Create a class called PersonAccount. It has firstname, lastname, incomes, expenses properties and it has total_income, total_expense, account_info, add_income, add_expense and account_balance methods. Incomes is a set of incomes and its description. The same goes for expenses. πŸŽ‰ CONGRATULATIONS ! πŸŽ‰ diff --git a/readme.md b/readme.md index 064fe881..827e7f31 100644 --- a/readme.md +++ b/readme.md @@ -188,7 +188,7 @@ Let us do some maths first before we write any Python code: - 2 + 3 is 5 - 3 - 2 is 1 -- 3 \* 2 is 6 +- 3 * 2 is 6 - 3 / 2 is 1.5 - 3 ** 2 is the same as 3 * 3 From 20f33ccbfc0f412e125b8c69bfdcbd9df3a661d4 Mon Sep 17 00:00:00 2001 From: Aren <95090911+rawbytedev@users.noreply.github.com> Date: Tue, 31 Dec 2024 23:01:41 +0100 Subject: [PATCH 2/2] uncomment --- 05_Day_Lists/day_5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/05_Day_Lists/day_5.py b/05_Day_Lists/day_5.py index 2959f999..9e7e1546 100644 --- a/05_Day_Lists/day_5.py +++ b/05_Day_Lists/day_5.py @@ -106,7 +106,7 @@ del fruits[1] print(fruits) # ['orange', 'lemon'] del fruits -#print(fruits) # This should give: NameError: name 'fruits' is not defined +print(fruits) # This should give: NameError: name 'fruits' is not defined # clear fruits = ['banana', 'orange', 'mango', 'lemon']