├── Day 17 ├── Day17 Solution.txt ├── README.md └── Python Syntax │ └── Day17 Syntax.py ├── Day 16 ├── Day16 Solution.txt ├── README.md └── Python Syntax │ └── Day16 Syntax.py ├── Day 23 └── README.md ├── Day 24 ├── README.md └── Python Syntax │ └── Day24 Syntax.py ├── Day 21 ├── Day21 Solution.txt ├── README.md └── Python Syntax │ └── Day21 Syntax.py ├── Day 15 ├── README.md ├── Day15 Solution.txt └── Python Syntax │ └── Day15 Syntax.py ├── Day 25 └── README.md ├── Day 22 ├── README.md ├── bu_stats.json ├── Python Syntax │ └── Day22 Syntax.py └── us_presidents.json ├── Day 13 ├── Day13 Syntax.py ├── Python Syntax │ └── Day13 Syntax.py └── README.md ├── Day 09 ├── Day09 Solution.txt ├── README.md └── Python Syntax │ └── Day09 Syntax.py ├── Day 08 ├── README.md ├── Day08 Solution.txt └── Python Syntax │ └── Day08 Syntax.py ├── Day 20 ├── README.md ├── Day20 Solution.txt └── Python Syntax │ └── Day20 Syntax.py ├── Day 18 ├── Day18 Solution.txt ├── README.md └── Python Syntax │ └── Day18 Syntax.py ├── Day 12 ├── Python Syntax │ ├── Day12_modules.py │ └── Day12 Syntax.py └── README.md ├── Day 02 ├── Day02 Solution.txt ├── README.md └── Python Syntax │ └── Day02 Syntax.py ├── Day 06 ├── README.md ├── Day06 Solution.txt └── Python Syntax │ └── Day06 Syntax.py ├── Day 07 ├── README.md ├── Day07 Solution.txt └── Python Syntax │ └── Day07 Syntax.py ├── Day 01 ├── README.md ├── Day01 Solution.txt └── Python Syntax │ └── Day01 Syntax.py ├── Day 10 ├── README.md └── Day10 Solution.txt ├── Day 03 ├── README.md ├── Day03 Solution.txt └── Python Syntax │ └── Day03 Syntax.py ├── Day 04 ├── Day04 Solution.txt └── README.md ├── Day 05 ├── README.md ├── countries.txt └── Day05 Solution.txt ├── Day 14 └── README.md ├── README.md ├── Day 11 ├── Day11 Solution.txt ├── README.md └── Python Syntax │ └── Day11 Syntax.py └── Day 19 ├── Day19 Solution.txt ├── README.md └── Python Syntax └── Day19 Syntax.py /Day 17/Day17 Solution.txt: -------------------------------------------------------------------------------- 1 | ----------------------------------------Exercise 17 Level 1 ---------------------------------------- 2 | names: ['Finland', 'Sweden', 'Norway', 'Denmark', 'Iceland', 'Estonia', 'Russia'] 3 | nordic: ['Finland', 'Sweden', 'Norway', 'Denmark', 'Iceland'] -------------------------------------------------------------------------------- /Day 16/Day16 Solution.txt: -------------------------------------------------------------------------------- 1 | ----------------------------------------Exercise 16 Level 1 ---------------------------------------- 2 | Number 1 3 | day = 28 4 | month = 11 5 | year = 2017 6 | hour = 23 7 | minute = 55 8 | timestamp = 1511931359.34238 9 | 10 | 11 | Number 2 12 | 11/28/2017, 23:55:59 13 | 14 | 15 | Number 3 16 | date_string = 5 December, 2019 17 | date_object = 2019-12-05 00:00:00 18 | 19 | 20 | Number 4 21 | Time difference: 33 days, 0:04:00.657620 22 | 23 | 24 | Number 5 25 | 17498 days, 23:55:59.342380 26 | Time difference: 17498 days -------------------------------------------------------------------------------- /Day 23/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Twenty three 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 23](#-exercises-day-23) 8 | 9 | 10 | ## Objective 11 | This repository contains the solution for the Day Twenty-Three of the "30 Days of Python Challenge"! 12 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 13 | 14 | 15 | ## 💻 Exercises: Day 23 16 | 17 | 1. Create a project directory with a virtual environment based on the example given above. 18 | 19 | 20 | 21 | [<< Day 22](../Day%2022/README.md) | [Day 24 >>](../Day%2024/README.md) 22 | -------------------------------------------------------------------------------- /Day 24/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Twenty Four 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 24](#-exercises-day-24) 8 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2024/Python%20Syntax/Day24%20Syntax.ipynb) 9 | 10 | ## Objective 11 | This repository contains the solution for the Day Twenty Four of the "30 Days of Python Challenge"! 12 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 13 | 14 | ## 💻 Exercises: Day 24 15 | 16 | 1. Repeat all the examples 17 | 18 | 19 | 20 | [<< Day 23](../Day%2023/README.md) | [Day 25 >>](../Day%2025/README.md) 21 | -------------------------------------------------------------------------------- /Day 21/Day21 Solution.txt: -------------------------------------------------------------------------------- 1 | ----------------------------------------Exercise 21 Level 1 ---------------------------------------- 2 | Number 1 3 | Count: 25 4 | Sum: 744 5 | Min: 24 6 | Max: 38 7 | Range: 14 8 | Mean: 29.76 9 | Median: 29 10 | Mode: {'mode': 26, 'count': 5} 11 | Standard Deviation: 4 12 | Variance: 18.27 13 | Frequency Distribution: 14 | Frequency distribution in percentage [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)] 15 | 16 | Number 2 17 | Name power shell 18 | Income {'Income1': 250000, 'Income2': 20000, 'Income3': 3000} 19 | Expenses: {'Expense1': 200000, 'Expense2': 5000, 'Expense3': 3000} 20 | Total Income: 273000 21 | Total Expenses: 208000 22 | -------------------------------------------------------------------------------- /Day 15/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Fifteen 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 15](#-exercises-day-15) 8 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2015/Python%20Syntax/Day15%20Syntax.py) 9 | 10 | ## Objective 11 | This repository contains the solution for the Day Fifteen of the "30 Days of Python Challenge"! 12 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 13 | 14 | ## 💻 Exercises: Day 15 15 | 16 | 17 | 1. Repeat the errors in the [section](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/15_Day_Python_type_errors/15_python_type_errors.md) 18 | 19 | 20 | [<< Day 14](../Day%2014/README.md) | [Day 16 >>](../Day%2016/README.md) 21 | 22 | 23 | --#### [Go to Top of Page](#objective) 24 | -------------------------------------------------------------------------------- /Day 15/Day15 Solution.txt: -------------------------------------------------------------------------------- 1 | ----------------------------------------Exercise 15 Level 1 ---------------------------------------- 2 | Number 1 3 | Syntax Error 4 | 5 | This happened at least 6 | Number 2 7 | 8 | Name Error 9 | Name Error 10 | name 'age' is not defined 11 | Number 3 12 | 13 | Index Error 14 | Index Error 15 | list index out of range 16 | Number 4 17 | 18 | Module Error 19 | ModuleNotFoundError 20 | No module named 'maths' 21 | Number 5 22 | 23 | Attribute Error 24 | Maybe you mean pi? 25 | module 'math' has no attribute 'PI' 26 | Number 6 27 | 28 | Key Error 29 | Check your dict key 30 | 'county' 31 | Number 7 32 | 33 | Type Error 34 | check the type of the data 35 | unsupported operand type(s) for +: 'int' and 'str' 36 | Number 8 37 | 38 | Zero Div Error 39 | Error - You divided by zero 40 | division by zero -------------------------------------------------------------------------------- /Day 17/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Seventeen 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 17](#-exercises-day-17) 8 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2017/Python%20Syntax/Day17%20Syntax.py) 9 | 10 | ## Objective 11 | This repository contains the solution for the Day Seventeen of the "30 Days of Python Challenge"! 12 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 13 | 14 | ## 💻 Exercises: Day 17 15 | 16 | 1. names = ['Finland', 'Sweden', 'Norway','Denmark','Iceland', 'Estonia','Russia']. Unpack the first five countries and store them in a variable nordic_countries, store Estonia and Russia in es, and ru respectively. 17 | 18 | 19 | [<< Day 16](../Day%2016/README.md) | [Day 18 >>](../Day%2018/README.md) 20 | 21 | 22 | --#### [Go to Top of Page](#objective) 23 | -------------------------------------------------------------------------------- /Day 25/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Twenty Five 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 25](#-exercises-day-25) 8 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2025/Python%20Syntax/Day25%20Syntax%20-Answers.ipynb) 9 | 10 | ## Objective 11 | This repository contains the solution for the Day Twenty Five of the "30 Days of Python Challenge"! 12 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 13 | 14 | ## 💻 Exercises: Day 25 15 | 16 | 1. Read the hacker_news.csv file from data directory 17 | 1. Get the first five rows 18 | 1. Get the last five rows 19 | 1. Get the title column as pandas series 20 | 1. Count the number of rows and columns 21 | - Filter the titles which contain python 22 | - Filter the titles which contain JavaScript 23 | - Explore the data and make sense of it 24 | 25 | 26 | [<< Day 24](../Day%2024/README.md) | [Day 26 >>](../Day%2026/README.md) 27 | -------------------------------------------------------------------------------- /Day 22/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Twenty two 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 22](#-exercises-day-22) 8 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2022/Python%20Syntax/Day22%20Syntax.py) 9 | 10 | ## Objective 11 | This repository contains the solution for the Day Twenty-Two of the "30 Days of Python Challenge"! 12 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 13 | 14 | 15 | ## 💻 Exercises: Day 22 16 | 17 | 1. Scrape the following website and store the data as json file(url = 'http://www.bu.edu/president/boston-university-facts-stats/'). 18 | 1. Extract the table in this url (https://archive.ics.uci.edu/ml/datasets.php) and change it to a json file 19 | 2. Scrape the presidents table and store the data as json(https://en.wikipedia.org/wiki/List_of_presidents_of_the_United_States). The table is not very structured and the scrapping may take very long time. 20 | 21 | 22 | 23 | [<< Day 21](../Day%2021/README.md) | [Day 23 >>](../Day%2023/README.md) 24 | -------------------------------------------------------------------------------- /Day 13/Day13 Syntax.py: -------------------------------------------------------------------------------- 1 | ----------------------------------------Day 13 Exercise level 1---------------------------------------- 2 | Number 1 3 | Original List: [-4, -3, -2, -1, 0, 2, 4, 6] 4 | [-4, -3, -2, -1, 0] 5 | 6 | 7 | Number 2 8 | Level 1 [[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]]] 9 | ==================================================== 10 | Last Level [1, 2, 3, 4, 5, 6, 7, 8, 9] 11 | 12 | Number 3 13 | [(0, 1, 0, 0, 0, 0, 0), 14 | (1, 1, 1, 1, 1, 1, 1), 15 | (2, 1, 2, 4, 8, 16, 32), 16 | (3, 1, 3, 9, 27, 81, 243), 17 | (4, 1, 4, 16, 64, 256, 1024), 18 | (5, 1, 5, 25, 125, 625, 3125), 19 | (6, 1, 6, 36, 216, 1296, 7776), 20 | (7, 1, 7, 49, 343, 2401, 16807), 21 | (8, 1, 8, 64, 512, 4096, 32768), 22 | (9, 1, 9, 81, 729, 6561, 59049), 23 | (10, 1, 10, 100, 1000, 10000, 100000)] 24 | 25 | Number 4 26 | [['FINLAND', 'FIN', 'HELSINKI'], ['SWEDEN', 'SWE', 'STOCKHOLM'], ['NORWAY', 'NOR', 'OSLO']] 27 | 28 | Number 5 29 | List of Dictionaries: [{'country': 'FINLAND', 'city': 'HELSINKI'}, {'country': 'SWEDEN', 'city': 'STOCKHOLM'}, {'country': 'NORWAY', 'city': 'OSLO'}] 30 | 31 | Number 6 32 | Combined List of Tuples: ['Asabeneh Yetayeh', 'David Smith', 'Donald Trump', 'Bill Gates'] 33 | -------------------------------------------------------------------------------- /Day 16/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Sixteen 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 16](#-exercises-day-16) 8 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2016/Python%20Syntax/Day16%20Syntax.py) 9 | 10 | ## Objective 11 | This repository contains the solution for the Day Sixteen of the "30 Days of Python Challenge"! 12 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 13 | 14 | ## 💻 Exercises: Day 16 15 | 16 | 1. Get the current day, month, year, hour, minute and timestamp from datetime module 17 | 1. Format the current date using this format: "%m/%d/%Y, %H:%M:%S") 18 | 1. Today is 5 December, 2019. Change this time string to time. 19 | 1. Calculate the time difference between now and new year. 20 | 1. Calculate the time difference between 1 January 1970 and now. 21 | 1. Think, what can you use the datetime module for? Examples: 22 | - Time series analysis 23 | - To get a timestamp of any activities in an application 24 | - Adding posts on a blog 25 | 26 | 27 | [<< Day 15](../Day%2015/README.md) | [Day 17 >>](../Day%2017/README.md) 28 | 29 | 30 | --#### [Go to Top of Page](#objective) 31 | -------------------------------------------------------------------------------- /Day 09/Day09 Solution.txt: -------------------------------------------------------------------------------- 1 | ----------------------------------------Day 9 Exercise level 1---------------------------------------- 2 | Number 1 3 | Enter your age: 4 | 15 5 | You need 3 more years to learn to drive. 6 | 7 | 8 | Number 2 9 | Enter your age, I am 25: 10 | 24 11 | You are 1 year younger than me 12 | 13 | Number 3 14 | Enter number one: 15 | 4 16 | Enter number two: 17 | 8 18 | 4 is smaller than 8 19 | 20 | ----------------------------------------Day 9 Exercise level 2---------------------------------------- 21 | Number 1 22 | Enter the student score: 23 | 89 24 | Your score: 89 has a grade of "A" 25 | 26 | 27 | Number 2 28 | Enter the month of the year: 29 | May 30 | The month of : May is "Spring" 31 | 32 | 33 | Number 3 34 | Enter a fruit: 35 | avocado 36 | Updated fruit list: ['banana', 'orange', 'mango', 'lemon', 'avocado'] 37 | 38 | 39 | ----------------------------------------Day 9 Exercise level 3---------------------------------------- 40 | Number 1 41 | skills exist 42 | Middle skill: ['Node'] 43 | 44 | 45 | Number 2 46 | Python is a skills present in the dictionary 47 | 48 | 49 | Number 3 50 | He is a full stack developer 51 | 52 | 53 | Number 4 54 | Asabeneh Yetayeh lives in Finland. He is married -------------------------------------------------------------------------------- /Day 24/Python Syntax/Day24 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day TwentyFour of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 03 Mar 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | # import the "re" module 16 | import re 17 | import collections 18 | import datetime 19 | from itertools import chain 20 | import json 21 | import csv 22 | import numpy as np 23 | import webbrowser 24 | import matplotlib as plt 25 | import requests 26 | import statistics 27 | import pandas as pd 28 | from bs4 import BeautifulSoup 29 | 30 | 31 | def main(): 32 | os.system("cls") # clear console 33 | 34 | def p(num): 35 | print(f"Number {num}") 36 | 37 | def pn(num = 1): 38 | print(f"\n" * num) 39 | 40 | def bannergreeting(day_name,exercise_name): 41 | daybanner = f'Exercise {day_name} ' 42 | exercisebanner = f'Level {exercise_name} ' 43 | front_end = f'--' * 20 44 | return combinebanners(front_end,daybanner,exercisebanner) 45 | 46 | def combinebanners(s0,s1,s2): 47 | return s0 + s1 + s2 + s0 48 | 49 | banner = bannergreeting 50 | print(banner(22,1)) 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | if __name__ == "__main__": 60 | main() 61 | -------------------------------------------------------------------------------- /Day 08/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Eight 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 8](#-exercises-day-8) 8 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2008/Python%20Syntax/Day08%20Syntax.py) 9 | 10 | ## Objective 11 | This repository contains the solution for the Day Eight of the "30 Days of Python Challenge"! 12 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 13 | 14 | ## 💻 Exercises: Day 8 15 | 16 | 1. Create an empty dictionary called dog 17 | 2. Add name, color, breed, legs, age to the dog dictionary 18 | 3. Create a student dictionary and add first_name, last_name, gender, age, marital status, skills, country, city and address as keys for the dictionary 19 | 4. Get the length of the student dictionary 20 | 5. Get the value of skills and check the data type, it should be a list 21 | 6. Modify the skills values by adding one or two skills 22 | 7. Get the dictionary keys as a list 23 | 8. Get the dictionary values as a list 24 | 9. Change the dictionary to a list of tuples using _items()_ method 25 | 10. Delete one of the items in the dictionary 26 | 11. Delete one of the dictionaries 27 | 28 | [<< Day 7](../Day%2007/README.md) | [Day 9 >>](../Day%2009/README.md) 29 | 30 | 31 | --#### [Go to Top of Page](#objective) 32 | -------------------------------------------------------------------------------- /Day 17/Python Syntax/Day17 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Seventeen of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 18 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | # import the "re" module 16 | import re 17 | import collections 18 | import datetime 19 | 20 | def main(): 21 | os.system("cls") # clear console 22 | 23 | def p(num): 24 | print(f"Number {num}") 25 | 26 | def pn(): 27 | print(f"\n") 28 | 29 | def bannergreeting(day_name,exercise_name): 30 | daybanner = f'Exercise {day_name} ' 31 | exercisebanner = f'Level {exercise_name} ' 32 | front_end = f'--' * 20 33 | return combinebanners(front_end,daybanner,exercisebanner) 34 | 35 | def combinebanners(s0,s1,s2): 36 | return s0 + s1 + s2 + s0 37 | 38 | banner = bannergreeting 39 | print(banner(17,1)) 40 | 41 | names = ['Finland', 'Sweden', 'Norway','Denmark','Iceland', 'Estonia','Russia'] 42 | #Unpack the first five countries and store them in a variable nordic_countries, store Estonia and Russia in es, and ru respectively 43 | *nordic,es, ru = names 44 | 45 | print("names:",names) 46 | print("nordic:",nordic) 47 | 48 | 49 | 50 | 51 | 52 | 53 | if __name__ == "__main__": 54 | main() 55 | -------------------------------------------------------------------------------- /Day 20/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Twenty 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 20](#-exercises-day-20) 8 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2020/Python%20Syntax/Day20%20Syntax.py) 9 | 10 | ## Objective 11 | This repository contains the solution for the Day Twenty of the "30 Days of Python Challenge"! 12 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 13 | 14 | 15 | ### 💻 Exercises: Day 20 16 | 17 | 1. Read this url and find the 10 most frequent words. romeo_and_juliet = 'http://www.gutenberg.org/files/1112/1112.txt' 18 | 2. Read the cats API and cats_api = 'https://api.thecatapi.com/v1/breeds' and find : 19 | 1. the min, max, mean, median, standard deviation of cats' weight in metric units. 20 | 2. the min, max, mean, median, standard deviation of cats' lifespan in years. 21 | 3. Create a frequency table of country and breed of cats 22 | 3. Read the [countries API](https://restcountries.eu/rest/v2/all) and find 23 | 1. the 10 largest countries 24 | 2. the 10 most spoken languages 25 | 3. the total number of languages in the countries API 26 | 4. UCI is one of the most common places to get data sets for data science and machine learning. Read the content of UCL (https://archive.ics.uci.edu/ml/datasets.php). Without additional libraries it will be difficult, so you may try it with BeautifulSoup4 27 | 28 | [<< Day 19](../Day%2019/README.md) | [Day 21 >>](../Day%2021/README.md) 29 | -------------------------------------------------------------------------------- /Day 22/bu_stats.json: -------------------------------------------------------------------------------- 1 | [{"Student Body": "33,678", "Living Alumni": "407,000+", "Total Employees": "10,406", "Faculty": "4,107", "Nondegree Students": "1,216", "Graduate & Professional Students": "15,932", "Undergraduate Students": "16,530"}, {"Classrooms": "850", "Buildings": "347", "Laboratories": "1,772", "Libraries": "12", "Campus Area (acres)": "175"}, {"Study Abroad Programs": "70+", "Average Class Size": "27", "Faculty": "4,107", "Student/Faculty Ratio": "10:1", "Schools and Colleges": "17", "Programs of Study": "300+"}, {"Research Expenditures": "$564.6M", "Research Awards": "$502.6M", "BMC Clinical Research Grants": "$110.0M"}, {"Average Total Need-Based Financial Aid": "$49,407", "Average Need-Based Grant/Scholarship": "$44,479", "Grants & Scholarships (need-based)": "$300.7M", "Grants & Scholarships (non-need-based)": "$27.8M"}, {"Community Service Hours": "1.6M+", "Alternative Service Breaks Participants": "300+", "BU on Social": "new accounts daily", "Cultural & Religious Organizations": "70+", "Community Service & Justice Organizations": "80+", "Academic & Professional Organizations": "140+", "Art & Performance Organizations": "60+", "Student Organizations": "450+", "First-Year Student Outreach Project Volunteers": "800+"}, {"Faculty Publications": "6,000+", "Student UROP Participants": "450+", "Centers & Institutes": "130+"}, {"Global Initiatives": "300+", "Cultural Student Groups": "50+", "Alumni Countries": "180+", "International Students": "11,000+"}, {"Intramural Sports & Tournaments": "12+", "Club and Intramural Sports Participants": "7,000+", "Club Sports Teams": "34", "Varsity Sports": "24"}] -------------------------------------------------------------------------------- /Day 18/Day18 Solution.txt: -------------------------------------------------------------------------------- 1 | ----------------------------------------Exercise 18 Level 1 ---------------------------------------- 2 | Split Words: ['I', 'love', 'teaching', 'If', 'you', 'do', 'not', 'love', 'teaching', 'what', 'else', 'can', 'you', 'love', 'I', 'love', 'Python', 'if', 'you', 'do', 'not', 'love', 'something', 'which', 'can', 'give', 'you', 'all', 'the', 'capabilities', 'to', 'develop', 'an', 'application', 'what', 'else', 'can', 'you', 'love'] 3 | 4 | 5 | Counter({'love': 6, 'you': 5, 'can': 3, 'I': 2, 'teaching': 2, 'do': 2, 'not': 2, 'what': 2, 'else': 2, 'If': 1, 'Python': 1, 'if': 1, 'something': 1, 'which': 1, 'give': 1, 'all': 1, 'the': 1, 'capabilities': 1, 'to': 1, 'develop': 1, 'an': 1, 'application': 1}) 6 | 7 | 8 | Final sorted Tuple: [(6, 'love'), (5, 'you'), (3, 'can'), (2, 'what'), (2, 'teaching'), (2, 'not'), (2, 'else'), (2, 'do'), (2, 'I'), (1, 'which'), (1, 'to'), (1, 'the'), (1, 'something'), (1, 'if'), (1, 'give'), (1, 'develop'), (1, 'capabilities'), (1, 'application'), (1, 'an'), (1, 'all'), (1, 'Python'), (1, 'If')] 9 | 10 | 11 | Number 2 12 | original list: ['-1', '2', '-4', '-3', '-1', '0', '4', '8'] 13 | sorted list: [-4, -3, -1, -1, 0, 2, 4, 8] 14 | distance = 8 - -4 = 12 15 | 16 | ----------------------------------------Exercise 18 Level 2 ---------------------------------------- 17 | Number 1 18 | first_name True 19 | first-name False 20 | 1first_name False 21 | firstname True 22 | ----------------------------------------Exercise 18 Level 3 ---------------------------------------- 23 | Number 1 24 | I am a teacher, and I love teaching. There is nothing as more rewarding as educating and empowering people. I found teaching more interesting than any other jobs. Does this motivate you to be a teacher? 25 | [(3, 'I'), (2, 'a'), (2, 'and')] 26 | -------------------------------------------------------------------------------- /Day 12/Python Syntax/Day12_modules.py: -------------------------------------------------------------------------------- 1 | # Modules supporting the Day 12 Syntax 2 | 3 | # import the "sys" module 4 | import sys 5 | # import the "os" module 6 | import os 7 | # import the "platform" module 8 | import platform 9 | # import the "platform" module 10 | import math 11 | # import the "re" module 12 | import re 13 | import random 14 | import secrets 15 | import string 16 | 17 | 18 | pool_of_xters = string.ascii_letters + string.digits 19 | def random_user_id(): 20 | user_id = '' 21 | for i in range(6): 22 | user_id += random.choice(pool_of_xters) 23 | return user_id 24 | 25 | def user_id_gen(num_of_xters,num_of_IDs): 26 | s = '' 27 | for i in range(num_of_IDs): 28 | for i in range(num_of_xters): 29 | s += random.choice(pool_of_xters) 30 | s +='\n' 31 | return s 32 | 33 | def rgb_color_gen(): 34 | color_rgb,a = (),[] 35 | for i in range(0,3): 36 | a.append(random.randint(0,255)) 37 | color_rgb = tuple(a) 38 | return f'rgb{color_rgb}' 39 | 40 | def list_of_hexa_colors(): 41 | hex_number = '#' 42 | for i in range(3): 43 | hex_number += hex(random.randint(0,255)).replace('0x','') 44 | #hex_number += str(re.split('0x',hex(random.randint(0,256)))) 45 | return hex_number 46 | 47 | def generate_colors(mode_color = 'hexa', num_color = 3): #default 48 | color_range=[] 49 | if mode_color == 'hexa': 50 | for i in range(num_color): 51 | color_range.append(list_of_hexa_colors()) 52 | else: 53 | for i in range(num_color): 54 | color_range.append(rgb_color_gen()) 55 | return color_range 56 | 57 | def shuffle_list(list1): 58 | set_to_return = len(list1) 59 | return random.sample(list1,k = set_to_return) 60 | 61 | def shuffle_list_9to7(list1): 62 | keyreturn = 7 63 | return random.sample(list1,k = 7) 64 | 65 | -------------------------------------------------------------------------------- /Day 02/Day02 Solution.txt: -------------------------------------------------------------------------------- 1 | Directory Variable Folder already exists 2 | File 'variables.py' created or updated 3 | @:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:Exercise level 2@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@: 4 | Variable: John is of data type:- 5 | Variable: Constantine is of data type:- 6 | Variable: John Constantine is of data type:- 7 | Variable: gitland is of data type:- 8 | Variable: gitville is of data type:- 9 | Variable: 18 is of data type:- 10 | Variable: 2022 is of data type:- 11 | Variable: False is of data type:- 12 | Variable: True is of data type:- 13 | Variable: True is of data type:- 14 | Length of firstname: "John" is 4 15 | Length of fullname: "John Constantine" is 16 16 | First Name is shorter than Last Name 17 | 9 18 | 1 19 | 20 20 | 1 21 | 625 22 | 1 23 | Enter a user-defined circle radius: 24 | 9 25 | Area of Circle with radius 9 meters is 254.47 26 | Please input your first name: 27 | John 28 | Please input your last name: 29 | Etrigan 30 | Please input your country 31 | Metropolis 32 | Please input your age 33 | 99 34 | 35 | Here is a list of the Python keywords. Enter any keyword to get more help. 36 | 37 | False class from or 38 | None continue global pass 39 | True def if raise 40 | and del import return 41 | as elif in try 42 | assert else is while 43 | async except lambda with 44 | await finally nonlocal yield 45 | break for not -------------------------------------------------------------------------------- /Day 06/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Six 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 6](#exercises-day-6) 8 | - [Exercise: Level 1](#exercise-level-1) 9 | - [Exercise: Level 2](#exercise-level-2) 10 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2006/Python%20Syntax/Day06%20Syntax.py) 11 | 12 | ## Objective 13 | This repository contains the solution for the Day Six of the "30 Days of Python Challenge"! 14 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 15 | 16 | ## 💻 Exercises: Day 6 17 | 18 | ### Exercise: Level 1 19 | 20 | 1. Create an empty tuple 21 | 2. Create a tuple containing names of your sisters and your brothers (imaginary siblings are fine) 22 | 3. Join brothers and sisters tuples and assign it to siblings 23 | 4. How many siblings do you have? 24 | 5. Modify the siblings tuple and add the name of your father and mother and assign it to family_members 25 | 26 | ### Exercise: Level 2 27 | 28 | 1. Unpack siblings and parents from family_members 29 | 1. Create fruits, vegetables and animal products tuples. Join the three tuples and assign it to a variable called food_stuff_tp. 30 | 1. Change the about food_stuff_tp tuple to a food_stuff_lt list 31 | 1. Slice out the middle item or items from the food_stuff_tp tuple or food_stuff_lt list. 32 | 1. Slice out the first three items and the last three items from food_staff_lt list 33 | 1. Delete the food_staff_tp tuple completely 34 | 1. Check if an item exists in tuple: 35 | 36 | - Check if 'Estonia' is a nordic country 37 | - Check if 'Iceland' is a nordic country 38 | 39 | ```py 40 | nordic_countries = ('Denmark', 'Finland','Iceland', 'Norway', 'Sweden') 41 | ``` 42 | 43 | 44 | [<< Day 5](../Day%2005/README.md) | [Day 7 >>](../Day%2007/README.md) 45 | 46 | 47 | --#### [Go to Top of Page](#objective) 48 | -------------------------------------------------------------------------------- /Day 07/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Seven 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 7](#exercises-day-7) 8 | - [Exercise: Level 1](#exercise-level-1) 9 | - [Exercise: Level 2](#exercise-level-2) 10 | - [Exercise: Level 3](#exercise-level-3) 11 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2007/Python%20Syntax/Day07%20Syntax.py) 12 | 13 | ## Objective 14 | This repository contains the solution for the Day Seven of the "30 Days of Python Challenge"! 15 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 16 | 17 | ## 💻 Exercises: Day 7 18 | 19 | ### Exercise: Level 1 20 | 21 | 22 | ```py 23 | # sets 24 | it_companies = {'Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon'} 25 | A = {19, 22, 24, 20, 25, 26} 26 | B = {19, 22, 20, 25, 26, 24, 28, 27} 27 | age = [22, 19, 24, 25, 26, 24, 25, 24] 28 | ``` 29 | *** 30 | 31 | ### Exercise: Level 1 32 | 33 | 1. Find the length of the set it_companies 34 | 2. Add 'Twitter' to it_companies 35 | 3. Insert multiple IT companies at once to the set it_companies 36 | 4. Remove one of the companies from the set it_companies 37 | 5. What is the difference between remove and discard 38 | 39 | ### Exercise: Level 2 40 | 41 | 1. Join A and B 42 | 1. Find A intersection B 43 | 1. Is A subset of B 44 | 1. Are A and B disjoint sets 45 | 1. Join A with B and B with A 46 | 1. What is the symmetric difference between A and B 47 | 1. Delete the sets completely 48 | 49 | ### Exercise: Level 3 50 | 51 | 1. Convert the ages to a set and compare the length of the list and the set, which one is bigger? 52 | 1. Explain the difference between the following data types: string, list, tuple and set 53 | 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. 54 | 55 | [<< Day 6](../Day%2006/README.md) | [Day 8 >>](../Day%2008/README.md) 56 | 57 | 58 | --#### [Go to Top of Page](#objective) 59 | -------------------------------------------------------------------------------- /Day 01/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day One 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 1](#-exercises---day-1) 8 | - [Exercise: Level 1](#exercise-level-1) 9 | - [Exercise: Level 2](#exercise-level-2) 10 | - [Exercise: Level 3](#exercise-level-3) 11 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2001/Python%20Syntax/Day01%20Syntax.py) 12 | 13 | ## Objective 14 | This repository contains the solution for the Day One of the "30 Days of Python Challenge"! 15 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 16 | 17 | 18 | ## 📘 Exercises - Day 1 19 | 20 | ### Exercise: Level 1 21 | 22 | 1. Check the python version you are using 23 | 2. Open the python interactive shell and do the following operations. The operands are 3 and 4. 24 | - addition(+) 25 | - subtraction(-) 26 | - multiplication(\*) 27 | - modulus(%) 28 | - division(/) 29 | - exponential(\*\*) 30 | - floor division operator(//) 31 | 3. Write strings on the python interactive shell. The strings are the following: 32 | - Your name 33 | - Your family name 34 | - Your country 35 | - I am enjoying 30 days of python 36 | 4. Check the data types of the following data: 37 | - 10 38 | - 9.8 39 | - 3.14 40 | - 4 - 4j 41 | - ['Asabeneh', 'Python', 'Finland'] 42 | - Your name 43 | - Your family name 44 | - Your country 45 | 46 | ### Exercise: Level 2 47 | 48 | 1. Create a folder named day_1 inside 30DaysOfPython folder. Inside day_1 folder, create a python file helloworld.py and repeat questions 1, 2, 3 and 4. Remember to use _print()_ when you are working on a python file. Navigate to the directory where you have saved your file, and run it. 49 | 50 | ### Exercise: Level 3 51 | 52 | 1. Write an example for different Python data types such as Number(Integer, Float, Complex), String, Boolean, List, Tuple, Set and Dictionary. 53 | 2. Find an [Euclidian distance](https://en.wikipedia.org/wiki/Euclidean_distance#:~:text=In%20mathematics%2C%20the%20Euclidean%20distance,being%20called%20the%20Pythagorean%20distance.) between (2, 3) and (10, 8) 54 | -------------------------------------------------------------------------------- /Day 08/Day08 Solution.txt: -------------------------------------------------------------------------------- 1 | ----------------------------------------Day 8 Exercise level 1---------------------------------------- 2 | Number 1 3 | Dog Dict: {} 4 | 5 | 6 | Number 2 7 | Dog Dict: {'name': 'Cujo', 'breed': 'St Bernard', 'legs': 4, 'age': 7} 8 | 9 | 10 | Number 3 11 | {'first_name': 'Harry', 'last_name': 'Potter', 'gender': 'male', 'age': 17, 'marital_status': 'Single', 'skills': 'wizardry', 'country': 'England', 'city': 'London', 'address': '100 Baker Street'} 12 | 13 | 14 | Number 4 15 | 9 16 | 17 | 18 | Number 5 19 | wizardry 20 | 21 | 22 | 23 | Number 6 24 | {'first_name': 'Harry', 'last_name': 'Potter', 'gender': 'male', 'age': 17, 'marital_status': 'Single', 'skills': 'wizardry', 'country': 'England', 'city': 'London', 'address': '100 Baker Street'} 25 | {'first_name': 'Harry', 'last_name': 'Potter', 'gender': 'male', 'age': 17, 'marital_status': 'Single', 'skills': ('wizardry', 'quidditch', 'flying'), 'country': 'England', 'city': 'London', 'address': '100 Baker Street'} 26 | 27 | 28 | Number 7 29 | Student Keys: dict_keys(['first_name', 'last_name', 'gender', 'age', 'marital_status', 'skills', 'country', 'city', 'address']) 30 | 31 | 32 | Number 8 33 | Student Value: dict_values(['Harry', 'Potter', 'male', 17, 'Single', ('wizardry', 'quidditch', 'flying'), 'England', 'London', '100 Baker Street']) 34 | 35 | 36 | Number 9 37 | Student Items as a Tuple: (('first_name', 'Harry'), ('last_name', 'Potter'), ('gender', 'male'), ('age', 17), ('marital_status', 'Single'), ('skills', ('wizardry', 'quidditch', 'flying')), ('country', 'England'), ('city', 'London'), ('address', '100 Baker Street')) 38 | 39 | Number 10 40 | Student Items before deletion {'first_name': 'Harry', 'last_name': 'Potter', 'gender': 'male', 'age': 17, 'marital_status': 'Single', 'skills': ('wizardry', 'quidditch', 'flying'), 'country': 'England', 'city': 'London', 'address': '100 Baker Street'} 41 | Student Items before deletion {'first_name': 'Harry', 'last_name': 'Potter', 'gender': 'male', 'age': 17, 'skills': ('wizardry', 'quidditch', 'flying'), 'country': 'England', 'city': 'London', 'address': '100 Baker Street'} 42 | 43 | 44 | Number 11 45 | Dict does not exist 46 | local variable 'student_dict' referenced before assignment 47 | -------------------------------------------------------------------------------- /Day 01/Day01 Solution.txt: -------------------------------------------------------------------------------- 1 | @:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:Exercise level 1@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@: 2 | Python version 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] 3 | Version info. sys.version_info(major=3, minor=10, micro=1, releaselevel='final', serial=0) 4 | 5 | 6 | Bonus -- Python Platfrom version 3.10.1 7 | 8 | 9 | a. Addition Operation: 3 + 4 equals 7 10 | b. Subtraction Operation: 3 - 4 equals -1 11 | c. Multiply Operation: 3 * 4 equals 12 12 | d. Modulo Operation: 3 % 4 equals 3 13 | e. Division Operation: 3 / 4 equals 0.75 14 | f1. Exponent Operation: 3 ** 4 equals 81 15 | g. Floor Division Operation: 3 // 4 equals 0 16 | f2. 'Bonus -- Exponent Operation: 3 pow 4 equals 81.0 17 | 18 | 19 | Please input your first name: 20 | data 21 | Please input your last name: 22 | Bio 23 | Please input your country 24 | Gitland 25 | Hello, My Name is data Bio from Gitland.I am enjoying 30 days of Python. 26 | 27 | Data: 10 is of data type:- 28 | Data: 9.8 is of data type:- 29 | Data: 3.14 is of data type:- 30 | Data: (4-4j) is of data type:- 31 | Data: ['Asabeneh', 'Python', 'Finland'] is of data type:- 32 | Data: data is of data type:- 33 | Data: Bio is of data type:- 34 | Data: Gitland is of data type:- 35 | @:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:Exercise level 2@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@: 36 | 37 | @:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:Exercise level 3@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@: 38 | Data: 5 is of data type:- 39 | Data: 13.2 is of data type:- 40 | Data: (-2+6j) is of data type:- 41 | Data: This is a string is of data type:- 42 | Data: True is of data type:- 43 | Data: [0, 1, 'two', 3.2, False] is of data type:- 44 | Data: (0, 1, 2) is of data type:- 45 | Data: {(3+2j), 'two', 2, 'one'} is of data type:- 46 | Data: {'one': 1, 'two': 2} is of data type:- 47 | 48 | The Euclidian distance between points(2, 3) and (10, 8) equals 9.43 49 | -------------------------------------------------------------------------------- /Day 13/Python Syntax/Day13 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Three of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: xx Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | from ast import comprehension 9 | import sys 10 | # import the "os" module 11 | import os 12 | # import the "platform" module 13 | import platform 14 | # import the "platform" module 15 | import math 16 | import re 17 | import copy 18 | 19 | def main(): 20 | 21 | os.system("cls") # clear console 22 | s1 = 'Day 13 Exercise level 1' 23 | s0 = '' 24 | 25 | for i in range(20): 26 | s0 += "--" 27 | 28 | s = s0 + s1 + s0 29 | print(s) 30 | 31 | print("Number 1") 32 | numbers = [-4, -3, -2, -1, 0, 2, 4, 6] 33 | list_neg_zero = [i for i in numbers if i <= 0] 34 | print("Original List:",numbers) 35 | print(list_neg_zero) 36 | print('\n') 37 | 38 | #2 Flatten the following list of lists of lists to a one dimensional list : 39 | print("Number 2") 40 | list_of_lists =[[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]]] #This is a 3D List of lists 41 | level2 = [level2 for level1 in list_of_lists for level2 in level1] 42 | print("Level 1", level2) 43 | 44 | #3 Using list comprehension create the following list of tuples 45 | print("Number 3") 46 | list_of_tuples_of_number = [(i,1,i,i ** 2, i **3, i **4, i ** 5) for i in range(11)] 47 | print(list_of_tuples_of_number) 48 | print('\n') 49 | 50 | #4 51 | x = [] 52 | for outerlist in countries: 53 | for inneritem in outerlist: 54 | temp_list = list(inneritem) 55 | temp_list.insert(1,temp_list[0][0:3]) 56 | i = [i.upper() for i in temp_list] 57 | x.append(i) 58 | print(x) 59 | 60 | #5 61 | print('Number 5') 62 | key_dict = ['country','city'] 63 | list_of_dict = [] 64 | for outerlist in countries: 65 | for inneritem in outerlist: 66 | temp_list = list(inneritem) 67 | i = [i.upper() for i in temp_list] 68 | i_dict = dict(zip(key_dict,i)) 69 | list_of_dict.append(i_dict) 70 | print("List of Dictionaries:", list_of_dict) 71 | 72 | #6 73 | names_to_compress = [[('Asabeneh', 'Yetayeh')], [('David', 'Smith')], [('Donald', 'Trump')], [('Bill', 'Gates')]] 74 | print('Number 6') 75 | list003 = [second_tuple[0] + ' ' + second_tuple[1] for first_tuple in names_to_compress for second_tuple in first_tuple ] 76 | print("Combined String List:", list003) 77 | print('\n' * 5) 78 | 79 | -------------------------------------------------------------------------------- /Day 16/Python Syntax/Day16 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Sixteen of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 18 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | # import the "re" module 16 | import re 17 | import collections 18 | from datetime import datetime, date, timedelta,time 19 | 20 | def main(): 21 | os.system("cls") # clear console 22 | 23 | def p(num): 24 | print(f"Number {num}") 25 | 26 | def pn(): 27 | print("\n") 28 | 29 | def bannergreeting(day_name,exercise_name): 30 | daybanner = f'Exercise {day_name} ' 31 | exercisebanner = f'Level {exercise_name} ' 32 | front_end = f'--' * 20 33 | return combinebanners(front_end,daybanner,exercisebanner) 34 | 35 | def combinebanners(s0,s1,s2): 36 | return s0 + s1 + s2 + s0 37 | 38 | banner = bannergreeting 39 | print(banner(16,1)) 40 | 41 | 42 | #1 Get the current day, month, year, hour, minute and timestamp from datetime module 43 | pn() 44 | p(1) 45 | timeObject1 = datetime(2017, 11, 28, 23, 55, 59, 342380) 46 | print("day =", timeObject1.day) 47 | print("month =", timeObject1.month) 48 | print("year =", timeObject1.year) 49 | print("hour =", timeObject1.hour) 50 | print("minute =", timeObject1.minute) 51 | print("timestamp =", timeObject1.timestamp()) 52 | pn() 53 | #2 Format the current date using this format: "%m/%d/%Y, %H:%M:%S") 54 | p(2) 55 | print(timeObject1.strftime("%m/%d/%Y, %H:%M:%S")) 56 | pn() 57 | 58 | #3 Today is 5 December, 2019. Change this time string to time. 59 | p(3) 60 | date_string = "5 December, 2019" 61 | print("date_string =", date_string) 62 | date_object = datetime.strptime(date_string, "%d %B, %Y") 63 | print("date_object =", date_object) 64 | pn() 65 | 66 | #4 Calculate the time difference between a time and new year. 67 | p(4) 68 | newyeartime = datetime(2018, 1, 1, 00, 00, 00, 00) 69 | time_diff = newyeartime - timeObject1 70 | print("Time difference:",time_diff) 71 | pn() 72 | 73 | #5 Calculate the time difference between 1 January 1970 and now. 74 | p(5) 75 | oldtime = datetime(1970, 1, 1, 00, 00, 00, 00) 76 | time_diff = timeObject1 - oldtime 77 | print(time_diff) 78 | print(f"Time difference: {time_diff.days} days") 79 | pn() 80 | 81 | 82 | if __name__ == "__main__": 83 | main() 84 | -------------------------------------------------------------------------------- /Day 13/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Thirteen 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 13](#-exercises-day-13) 8 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2013/Python%20Syntax/Day13%20Syntax.py) 9 | 10 | ## Objective 11 | This repository contains the solution for the Day One of the "30 Days of Python Challenge"! 12 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 13 | 14 | 15 | ## 💻 Exercises: Day 13 16 | 17 | 1. Filter only negative and zero in the list using list comprehension 18 | ```py 19 | numbers = [-4, -3, -2, -1, 0, 2, 4, 6] 20 | ``` 21 | 2. Flatten the following list of lists of lists to a one dimensional list : 22 | 23 | ```py 24 | list_of_lists =[[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]]] 25 | 26 | output 27 | [1, 2, 3, 4, 5, 6, 7, 8, 9] 28 | ``` 29 | 30 | 3. Using list comprehension create the following list of tuples: 31 | ```py 32 | [(0, 1, 0, 0, 0, 0, 0), 33 | (1, 1, 1, 1, 1, 1, 1), 34 | (2, 1, 2, 4, 8, 16, 32), 35 | (3, 1, 3, 9, 27, 81, 243), 36 | (4, 1, 4, 16, 64, 256, 1024), 37 | (5, 1, 5, 25, 125, 625, 3125), 38 | (6, 1, 6, 36, 216, 1296, 7776), 39 | (7, 1, 7, 49, 343, 2401, 16807), 40 | (8, 1, 8, 64, 512, 4096, 32768), 41 | (9, 1, 9, 81, 729, 6561, 59049), 42 | (10, 1, 10, 100, 1000, 10000, 100000)] 43 | ``` 44 | 4. Flatten the following list to a new list: 45 | ```py 46 | countries = [[('Finland', 'Helsinki')], [('Sweden', 'Stockholm')], [('Norway', 'Oslo')]] 47 | output: 48 | [['FINLAND','FIN', 'HELSINKI'], ['SWEDEN', 'SWE', 'STOCKHOLM'], ['NORWAY', 'NOR', 'OSLO']] 49 | ``` 50 | 5. Change the following list to a list of dictionaries: 51 | ```py 52 | countries = [[('Finland', 'Helsinki')], [('Sweden', 'Stockholm')], [('Norway', 'Oslo')]] 53 | output: 54 | [{'country': 'FINLAND', 'city': 'HELSINKI'}, 55 | {'country': 'SWEDEN', 'city': 'STOCKHOLM'}, 56 | {'country': 'NORWAY', 'city': 'OSLO'}] 57 | ``` 58 | 6. Change the following list of lists to a list of concatenated strings: 59 | ```py 60 | names = [[('Asabeneh', 'Yetayeh')], [('David', 'Smith')], [('Donald', 'Trump')], [('Bill', 'Gates')]] 61 | output 62 | ['Asabeneh Yetaeyeh', 'David Smith', 'Donald Trump', 'Bill Gates'] 63 | ``` 64 | 7. Write a lambda function which can solve a slope or y-intercept of linear functions. 65 | 66 | [<< Day 12](../Day%2012/README.md) | [Day 14 >>](../Day%2014/README.md) 67 | 68 | 69 | --#### [Go to Top of Page](#objective) 70 | -------------------------------------------------------------------------------- /Day 06/Day06 Solution.txt: -------------------------------------------------------------------------------- 1 | @:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:Exercise level 1@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@: 2 | Number 1 3 | Empty Tuple: () 4 | Empty Tuple: () 5 | 6 | 7 | Number 2 8 | Tuple - Brothers: ('Luke Skywalker', 'Obi-Wan Kenobi', 'Mace Windu') 9 | Tuple - Sisters: ('Ahsoka Tahno', 'Leia Organa', 'Padme Amidala') 10 | 11 | 12 | Number 3 13 | Tuple - Siblings: ('Luke Skywalker', 'Obi-Wan Kenobi', 'Mace Windu', 'Ahsoka Tahno', 'Leia Organa', 'Padme Amidala') 14 | Method 2- Using List to modify tuples workaround: ('Luke Skywalker', 'Obi-Wan Kenobi', 'Mace Windu', 'Ahsoka Tahno', 'Leia Organa', 'Padme Amidala') 15 | 16 | 17 | Number 4 18 | Number of Siblings: 6 19 | 20 | 21 | Number 5 22 | Family Tuple: ('Luke Skywalker', 'Obi-Wan Kenobi', 'Mace Windu', 'Ahsoka Tahno', 'Leia Organa', 'Padme Amidala', ('Master Yoda', 'Emperor Palpatine')) 23 | 24 | 25 | @:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:Exercise level 2@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@: 26 | Number 1 27 | Sibling: ['Luke Skywalker', 'Obi-Wan Kenobi', 'Mace Windu', 'Ahsoka Tahno', 'Leia Organa', 'Padme Amidala'] 28 | Parents: ('Master Yoda', 'Emperor Palpatine') 29 | 30 | 31 | Number 2 32 | Tuple 1: ('banana', 'orange', 'mango', 'lemon') 33 | Tuple 2: ('Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot') 34 | Tuple 3: ('fat', 'meat', 'milk', 'eggs') 35 | Combined Foodstuff Tuples: ('banana', 'orange', 'mango', 'lemon', 'Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot', 'fat', 'meat', 'milk', 'eggs') 36 | 37 | 38 | Number 3 39 | Combined Foodstuff Lists: ['banana', 'orange', 'mango', 'lemon', 'Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot', 'fat', 'meat', 'milk', 'eggs'] 40 | 41 | Number 4 42 | List: ('banana', 'orange', 'mango', 'lemon', 'Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot', 'fat', 'meat', 'milk', 'eggs') 43 | Length: 13 44 | Middle Food Tuple: ('Cabbage',) 45 | 46 | Number 5 47 | Foodstuff Tuples: ('banana', 'orange', 'mango', 'lemon', 'Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot', 'fat', 'meat', 'milk', 'eggs') 48 | With First 3 out: ('lemon', 'Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot', 'fat', 'meat', 'milk', 'eggs') 49 | 50 | 51 | With Last 3 out: ('banana', 'orange', 'mango', 'lemon', 'Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot', 'fat') 52 | 53 | 54 | Number 6 55 | Tuple does not exist! 56 | local variable 'food_stuff_tp' referenced before assignment 57 | 58 | 59 | Number 7 60 | No, Estonia does not exists in ('Denmark', 'Finland', 'Iceland', 'Norway', 'Sweden') 61 | Yes, Iceland exists in ('Denmark', 'Finland', 'Iceland', 'Norway', 'Sweden') 62 | -------------------------------------------------------------------------------- /Day 15/Python Syntax/Day15 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Fifteen of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 18 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | # import the "re" module 16 | import re 17 | 18 | def main(): 19 | os.system("cls") # clear console 20 | 21 | def p(num): 22 | print(f"Number {num}") 23 | 24 | def pn(): 25 | print(f"\n") 26 | 27 | def bannergreeting(day_name,exercise_name): 28 | daybanner = f'Exercise {day_name} ' 29 | exercisebanner = f'Level {exercise_name} ' 30 | front_end = f'--' * 20 31 | return combinebanners(front_end,daybanner,exercisebanner) 32 | 33 | def combinebanners(s0,s1,s2): 34 | return s0 + s1 + s2 + s0 35 | 36 | banner = bannergreeting 37 | print(banner(15,1)) 38 | 39 | p(1) 40 | print('Syntax Error\n') 41 | try: 42 | #print 'hello world' #SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)? 43 | pass 44 | except SyntaxError as e: 45 | print("Syntax Error") 46 | print(e) 47 | finally: 48 | print("This happened at least") 49 | pn 50 | 51 | p(2) 52 | print('\nName Error') 53 | try: 54 | print(age) #'age' is not defined 55 | except NameError as e: 56 | print("Name Error") 57 | print(e) 58 | 59 | p(3) 60 | print('\nIndex Error') 61 | numbers = [1, 2, 3, 4, 5] 62 | try: 63 | print(numbers[5]) 64 | except IndexError as e: 65 | print("Index Error") 66 | print(e) 67 | 68 | p(4) 69 | print('\nModule Error') 70 | try: 71 | import maths 72 | except ModuleNotFoundError as e: 73 | print("ModuleNotFoundError") 74 | print(e) 75 | 76 | p(5) 77 | print('\nAttribute Error') 78 | try: 79 | import math 80 | print(math.PI) 81 | except AttributeError as e: 82 | print("Maybe you mean pi?") 83 | print(e) 84 | 85 | p(6) 86 | print('\nKey Error') 87 | users = {'name':'Asab', 'age':250, 'country':'Finland'} 88 | try: 89 | print(users['county']) 90 | except KeyError as e: 91 | print("Check your dict key") 92 | print(e) 93 | 94 | p(7) 95 | print('\nType Error') 96 | try: 97 | x = 4 + '3' 98 | print(x) 99 | except TypeError as e: 100 | print("check the type of the data") 101 | print(e) 102 | 103 | p(8) 104 | print('\nZero Div Error') 105 | try: 106 | x = 10/0 107 | print(x) 108 | except ZeroDivisionError as e: 109 | print("Error - You divided by zero") 110 | print(e) 111 | 112 | 113 | 114 | if __name__ == "__main__": 115 | main() 116 | -------------------------------------------------------------------------------- /Day 02/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Two 4 | 5 | ## 📚 Table of Contents 6 | - [💻 Exercises - Day 1](#-exercises---day-2) 7 | - [Exercise: Level 1](#exercises-level-1) 8 | - [Exercise: Level 2](#exercises-level-2) 9 | - [Syntax on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2002/Python%20Syntax/Day02%20Syntax.py) 10 | 11 | ## 💻 Exercises - Day 2 12 | 13 | ### Exercises: Level 1 14 | 15 | 1. Inside 30DaysOfPython create a folder called day_2. Inside this folder create a file named variables.py 16 | 2. Write a python comment saying 'Day 2: 30 Days of python programming' 17 | 3. Declare a first name variable and assign a value to it 18 | 4. Declare a last name variable and assign a value to it 19 | 5. Declare a full name variable and assign a value to it 20 | 6. Declare a country variable and assign a value to it 21 | 7. Declare a city variable and assign a value to it 22 | 8. Declare an age variable and assign a value to it 23 | 9. Declare a year variable and assign a value to it 24 | 10. Declare a variable is_married and assign a value to it 25 | 11. Declare a variable is_true and assign a value to it 26 | 12. Declare a variable is_light_on and assign a value to it 27 | 13. Declare multiple variable on one line 28 | 29 | ### Exercises: Level 2 30 | 31 | 1. Check the data type of all your variables using type() built-in function 32 | 1. Using the _len()_ built-in function, find the length of your first name 33 | 1. Compare the length of your first name and your last name 34 | 1. Declare 5 as num_one and 4 as num_two 35 | 1. Add num_one and num_two and assign the value to a variable total 36 | 2. Subtract num_two from num_one and assign the value to a variable diff 37 | 3. Multiply num_two and num_one and assign the value to a variable product 38 | 4. Divide num_one by num_two and assign the value to a variable division 39 | 5. Use modulus division to find num_two divided by num_one and assign the value to a variable remainder 40 | 6. Calculate num_one to the power of num_two and assign the value to a variable exp 41 | 7. Find floor division of num_one by num_two and assign the value to a variable floor_division 42 | 1. The radius of a circle is 30 meters. 43 | 1. Calculate the area of a circle and assign the value to a variable name of _area_of_circle_ 44 | 2. Calculate the circumference of a circle and assign the value to a variable name of _circum_of_circle_ 45 | 3. Take radius as user input and calculate the area. 46 | 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 47 | 1. Run help('keywords') in Python shell or in your file to check for the Python reserved words or keywords 48 | 49 | 🎉 CONGRATULATIONS ! 🎉 50 | -------------------------------------------------------------------------------- /Day 21/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Twenty One 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 21](#-exercises-day-21) 8 | - [Exercises: Level 1](#exercises-level-1) 9 | - [Exercises: Level 2](#exercises-level-2) 10 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2021/Python%20Syntax/Day21%20Syntax.py) 11 | 12 | ## Objective 13 | This repository contains the solution for the Day Twenty-One of the "30 Days of Python Challenge"! 14 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 15 | 16 | 17 | ## 💻 Exercises: Day 21 18 | 19 | ### Exercises: Level 1 20 | 21 | 1. Python has the module called _statistics_ and we can use this module to do all the statistical calculations. However, to learn how to make function and reuse function let us try to develop a program, which calculates the measure of central tendency of a sample (mean, median, mode) and measure of variability (range, variance, standard deviation). In addition to those measures, find the min, max, count, percentile, and frequency distribution of the sample. You can create a class called Statistics and create all the functions that do statistical calculations as methods for the Statistics class. Check the output below. 22 | 23 | ```py 24 | ages = [31, 26, 34, 37, 27, 26, 32, 32, 26, 27, 27, 24, 32, 33, 27, 25, 26, 38, 37, 31, 34, 24, 33, 29, 26] 25 | 26 | print('Count:', data.count()) # 25 27 | print('Sum: ', data.sum()) # 744 28 | print('Min: ', data.min()) # 24 29 | print('Max: ', data.max()) # 38 30 | print('Range: ', data.range() # 14 31 | print('Mean: ', data.mean()) # 30 32 | print('Median: ', data.median()) # 29 33 | print('Mode: ', data.mode()) # {'mode': 26, 'count': 5} 34 | print('Standard Deviation: ', data.std()) # 4.2 35 | print('Variance: ', data.var()) # 17.5 36 | print('Frequency Distribution: ', data.freq_dist()) # [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)] 37 | ``` 38 | 39 | ```sh 40 | # you output should look like this 41 | print(data.describe()) 42 | Count: 25 43 | Sum: 744 44 | Min: 24 45 | Max: 38 46 | Range: 14 47 | Mean: 30 48 | Median: 29 49 | Mode: (26, 5) 50 | Variance: 17.5 51 | Standard Deviation: 4.2 52 | Frequency Distribution: [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)] 53 | ``` 54 | 55 | ### Exercises: Level 2 56 | 57 | 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. 58 | 59 | 60 | 61 | [<< Day 20](../Day%2020/README.md) | [Day 22 >>](../Day%2022/README.md) 62 | -------------------------------------------------------------------------------- /Day 12/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Twelve 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 12](#-exercises-day-12) 8 | - [Exercise: Level 1](#exercises-level-1) 9 | - [Exercise: Level 2](#exercises-level-2) 10 | - [Exercise: Level 3](#exercises-level-3) 11 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2012/Python%20Syntax/Day12%20Syntax.py) 12 | 13 | ## Objective 14 | This repository contains the solution for the Day Twelve of the "30 Days of Python Challenge"! 15 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 16 | 17 | ## 💻 Exercises: Day 12 18 | 19 | ### Exercises: Level 1 20 | 21 | 1. Writ a function which generates a six digit/character random_user_id. 22 | ```py 23 | print(random_user_id()); 24 | '1ee33d' 25 | ``` 26 | 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. 27 | 28 | ```py 29 | print(user_id_gen_by_user()) # user input: 5 5 30 | #output: 31 | #kcsy2 32 | #SMFYb 33 | #bWmeq 34 | #ZXOYh 35 | #2Rgxf 36 | 37 | print(user_id_gen_by_user()) # 16 5 38 | #1GCSgPLMaBAVQZ26 39 | #YD7eFwNQKNs7qXaT 40 | #ycArC5yrRupyG00S 41 | #UbGxOFI7UXSWAyKN 42 | #dIV0SSUTgAdKwStr 43 | ``` 44 | 45 | 3. Write a function named rgb_color_gen. It will generate rgb colors (3 values ranging from 0 to 255 each). 46 | 47 | ```py 48 | print(rgb_color_gen()) 49 | # rgb(125,244,255) - the output should be in this form 50 | ``` 51 | 52 | ### Exercises: Level 2 53 | 54 | 1. Write a function list_of_hexa_colors which returns any number of hexadecimal colors in an array (six hexadecimal numbers written after #. Hexadecimal numeral system is made out of 16 symbols, 0-9 and first 6 letters of the alphabet, a-f. Check the task 6 for output examples). 55 | 1. Write a function list_of_rgb_colors which returns any number of RGB colors in an array. 56 | 1. Write a function generate_colors which can generate any number of hexa or rgb colors. 57 | 58 | ```py 59 | generate_colors('hexa', 3) # ['#a3e12f','#03ed55','#eb3d2b'] 60 | generate_colors('hexa', 1) # ['#b334ef'] 61 | generate_colors('rgb', 3) # ['rgb(5, 55, 175','rgb(50, 105, 100','rgb(15, 26, 80'] 62 | generate_colors('rgb', 1) # ['rgb(33,79, 176)'] 63 | ``` 64 | 65 | ### Exercises: Level 3 66 | 67 | 1. Call your function shuffle_list, it takes a list as a parameter and it returns a shuffled list 68 | 1. Write a function which returns an array of seven random numbers in a range of 0-9. All the numbers must be unique. 69 | 70 | 71 | [<< Day 11](../Day%2011/README.md) | [Day 123 >>](../Day%2013/README.md) 72 | 73 | 74 | --#### [Go to Top of Page](#objective) 75 | -------------------------------------------------------------------------------- /Day 12/Python Syntax/Day12 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Twelve of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 12 Feb 2022 5 | # IDE: VSCode 6 | 7 | from Day12_modules import * 8 | 9 | def main(): 10 | 11 | s1 = 'Day 12 Exercise level 1' 12 | s2 = 'Day 12 Exercise level 2' 13 | s3 = 'Day 12 Exercise level 3' 14 | s0 = '' 15 | 16 | for i in range(20): 17 | s0 += "--" 18 | 19 | s = s0 + s1 + s0 20 | print(s) 21 | os.system("cls") # clear console 22 | 23 | print("Bonus - Secrets hex:", secrets.token_hex(3)) #for passwords 24 | 25 | #1 Write a function which generates a six digit/character random_user_id. 26 | # print(random_user_id()); 27 | # '1ee33d' 28 | 29 | # print(string.ascii_letters) # alphanumerics 30 | # print(string.digits) # digits 31 | 32 | print("Number 1") 33 | print(random_user_id()) 34 | print("\n") 35 | 36 | #2 Modify the previous task. Declare a function named user_id_gen_by_user. 37 | # It doesn’t take any parameters but it takes two inputs using input(). 38 | # One of the inputs is the number of characters and the second input is the number of IDs which are supposed to be generated. 39 | 40 | print("Number 2") 41 | print(user_id_gen(5,5)) 42 | #To get multi input use split() 43 | str_input = input("Enter the number of characters and number of IDs required seperated, -by a space or hyphen:\n") 44 | #split using white space 45 | a, b,*rest = [i for i in re.split(" |:|-\n",str_input)] 46 | num_char, num_of_id = int(a), int(b) 47 | print('#output') 48 | print(user_id_gen(num_char, num_of_id)) 49 | 50 | print("Number 3") 51 | print(rgb_color_gen()) 52 | print('\n') 53 | 54 | #2 Write a function list_of_hexa_colors which returns any number of hexadecimal colors in an array (six hexadecimal numbers written after #. 55 | # Hexadecimal numeral system is made out of 16 symbols, 0-9 and first 6 letters of the alphabet, a-f. Check the task 6 for output examples). 56 | 57 | s = s0 + s2 + s0 58 | print(s) 59 | 60 | print("Number 1") 61 | print(list_of_hexa_colors()) 62 | print('\n') 63 | 64 | print("Number 2") 65 | print(generate_colors('hexa', 3)) 66 | print(generate_colors('hexa', 1)) 67 | print(generate_colors('rgb', 3)) 68 | print(generate_colors('rgb', 1)) 69 | print(generate_colors()) 70 | print(generate_colors('rgb')) 71 | print('\n') 72 | 73 | s = s0 + s3 + s0 74 | print(s) 75 | # Exercises: Level 3 76 | # 1. Call your function shuffle_list, it takes a list as a parameter and it returns a shuffled list 77 | list1 = ['banana', 'cherry', 'apple'] 78 | list2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,20] 79 | 80 | print(shuffle_list(list1)) 81 | print(shuffle_list(list2)) 82 | 83 | # 2. Write a function which returns an array of seven random numbers in a range of 0-9. All the numbers must be unique. 84 | list3 = [0,1, 2, 3, 4, 5, 6, 7, 8, 9] 85 | print(shuffle_list_9to7(list3)) 86 | 87 | 88 | 89 | if __name__ == "__main__": 90 | main() 91 | -------------------------------------------------------------------------------- /Day 10/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Ten 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 10](#-exercises-day-10) 8 | - [Exercise: Level 1](#exercises-level-1) 9 | - [Exercise: Level 2](#exercises-level-2) 10 | - [Exercise: Level 3](#exercises-level-3) 11 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2010/Python%20Syntax/Day10%20Syntax.py) 12 | 13 | ## Objective 14 | This repository contains the solution for the Day Ten of the "30 Days of Python Challenge"! 15 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 16 | 17 | ## 💻 Exercises: Day 10 18 | 19 | ### Exercises: Level 1 20 | 21 | 1. Iterate 0 to 10 using for loop, do the same using while loop. 22 | 2. Iterate 10 to 0 using for loop, do the same using while loop. 23 | 3. Write a loop that makes seven calls to print(), so we get on the output the following triangle: 24 | 25 | ```py 26 | # 27 | ## 28 | ### 29 | #### 30 | ##### 31 | ###### 32 | ####### 33 | ``` 34 | 35 | 4. Use nested loops to create the following: 36 | 37 | ```sh 38 | # # # # # # # # 39 | # # # # # # # # 40 | # # # # # # # # 41 | # # # # # # # # 42 | # # # # # # # # 43 | # # # # # # # # 44 | # # # # # # # # 45 | # # # # # # # # 46 | ``` 47 | 48 | 5. Print the following pattern: 49 | 50 | ```sh 51 | 0 x 0 = 0 52 | 1 x 1 = 1 53 | 2 x 2 = 4 54 | 3 x 3 = 9 55 | 4 x 4 = 16 56 | 5 x 5 = 25 57 | 6 x 6 = 36 58 | 7 x 7 = 49 59 | 8 x 8 = 64 60 | 9 x 9 = 81 61 | 10 x 10 = 100 62 | ``` 63 | 64 | 6. Iterate through the list, ['Python', 'Numpy','Pandas','Django', 'Flask'] using a for loop and print out the items. 65 | 7. Use for loop to iterate from 0 to 100 and print only even numbers 66 | 8. Use for loop to iterate from 0 to 100 and print only odd numbers 67 | 68 | ### Exercises: Level 2 69 | 70 | 1. Use for loop to iterate from 0 to 100 and print the sum of all numbers. 71 | 72 | ```sh 73 | The sum of all numbers is 5050. 74 | ``` 75 | 76 | 1. Use for loop to iterate from 0 to 100 and print the sum of all evens and the sum of all odds. 77 | 78 | ```sh 79 | The sum of all evens is 2550. And the sum of all odds is 2500. 80 | ``` 81 | 82 | ### Exercises: Level 3 83 | 84 | 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_. 85 | 1. This is a fruit list, ['banana', 'orange', 'mango', 'lemon'] reverse the order using loop. 86 | 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. 87 | 1. What are the total number of languages in the data 88 | 2. Find the ten most spoken languages from the data 89 | 3. Find the 10 most populated countries in the world 90 | 91 | [<< Day 9](../Day%2009/README.md) | [Day 11 >>](../Day%2011/README.md) 92 | 93 | 94 | --#### [Go to Top of Page](#objective) 95 | 96 | -------------------------------------------------------------------------------- /Day 07/Day07 Solution.txt: -------------------------------------------------------------------------------- 1 | ----------------------------------------Day 7 Exercise level 1---------------------------------------- 2 | Number 1 3 | 7 4 | 5 | 6 | Number 2 7 | original set: {'IBM', 'Microsoft', 'Google', 'Oracle', 'Amazon', 'Facebook', 'Apple'} 8 | Adding twitter to set: {'Twitter', 'IBM', 'Microsoft', 'Google', 'Oracle', 'Amazon', 'Facebook', 'Apple'} 9 | 10 | 11 | Number 3 12 | original set: {'Twitter', 'IBM', 'Microsoft', 'Google', 'Oracle', 'Amazon', 'Facebook', 'Apple'} 13 | Adding new set to set - update removes duplicates: 14 | {'IBM', 'Microsoft', 'Dell', 'Alibaba', 'Amazon', 'Twitter', 'Google', 'Oracle', 'Netflix', 'Facebook', 'Apple'} 15 | 16 | 17 | Number 4 18 | Remove Netflix from set: {'Apple', 'Oracle', 'Microsoft', 'Dell', 'IBM', 'Twitter', 'Alibaba', 'Facebook', 'Google', 'Amazon'} 19 | 20 | 21 | Number 5 22 | The remove() method will 23 | raise an error if the specified item does not exist, 24 | and the discard() method will not. 25 | 26 | 27 | ----------------------------------------Day 7 Exercise level 2---------------------------------------- 28 | Number 1 29 | Set A: {19, 20, 22, 24, 25, 26} 30 | Set B: {19, 20, 22, 24, 25, 26, 27, 28} 31 | A updated with B: {19, 20, 22, 24, 25, 26, 27, 28} 32 | Method 2 using Union(): {19, 20, 22, 24, 25, 26, 27, 28} 33 | 34 | 35 | Number 2 36 | Set A: {19, 20, 22, 24, 25, 26} 37 | Set B: {19, 20, 22, 24, 25, 26, 27, 28} 38 | A intersection B: {19, 20, 22, 24, 25, 26} 39 | 40 | 41 | Number 3 42 | Set A: {19, 20, 22, 24, 25, 26} 43 | Set B: {19, 20, 22, 24, 25, 26, 27, 28} 44 | A is a subset of B 45 | 46 | 47 | Number 4 48 | Set A: {19, 20, 22, 24, 25, 26} 49 | Set B: {19, 20, 22, 24, 25, 26, 27, 28} 50 | A and B is not disjoint 51 | 52 | 53 | Number 5 54 | Set A: {19, 20, 22, 24, 25, 26} 55 | Set B: {19, 20, 22, 24, 25, 26, 27, 28} 56 | A joined with B: {19, 20, 22, 24, 25, 26, 27, 28} 57 | B joined with A: {19, 20, 22, 24, 25, 26, 27, 28} 58 | 59 | 60 | Number 6 61 | Set A: {19, 20, 22, 24, 25, 26} 62 | Set B: {19, 20, 22, 24, 25, 26, 27, 28} 63 | A symmetric difference: {27, 28} 64 | Bonus:difference of A and B set() 65 | 66 | 67 | The difference is an emppty set as A is contained within B 68 | 69 | 70 | Number 7 71 | Set does not exist 72 | local variable 'A' referenced before assignment 73 | 74 | 75 | ----------------------------------------Day 7 Exercise level 3---------------------------------------- 76 | Number 1 77 | Age Set: {19, 22, 24, 25, 26} 78 | Age List: [22, 19, 24, 25, 26, 24, 25, 24] 79 | List is bigger 80 | 81 | 82 | Number 2 83 | List items are ordered, changeable, allow duplicates and use square brackets 84 | Tuple items are ordered, unchangeable, allow duplicates and use round brackets 85 | Sets are unordered,unindexed, unchangeable, do not allow duplicates and use curly braces 86 | Dicts are ordered,indexed with key names, changeable, do not allow duplicates and use curly braces 87 | 88 | 89 | Number 3 90 | ['I', 'am', 'a', 'teacher', 'and', 'I', 'love', 'to', 'inspire', 'and', 'teach', 'people'] 91 | Unique words in the string: 10 92 | Total words in the sentence: 12 -------------------------------------------------------------------------------- /Day 03/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Three 4 | 5 | ## 📚 Table of Contents 6 | - [💻 Exercises - Day 3](#-exercises---day-3) 7 | - [Syntax on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2003/Python%20Syntax/Day03%20Syntax.py) 8 | 9 | ## 💻 Exercises - Day 3 10 | 11 | 1. Declare your age as integer variable 12 | 2. Declare your height as a float variable 13 | 3. Declare a variable that store a complex number 14 | 4. Write a script that prompts the user to enter base and height of the triangle and calculate an area of this triangle (area = 0.5 x b x h). 15 | 16 | ```py 17 | Enter base: 20 18 | Enter height: 10 19 | The area of the triangle is 100 20 | ``` 21 | 22 | 5. Write a script that prompts the user to enter side a, side b, and side c of the triangle. Calculate the perimeter of the triangle (perimeter = a + b + c). 23 | 24 | ```py 25 | Enter side a: 5 26 | Enter side b: 4 27 | Enter side c: 3 28 | The perimeter of the triangle is 12 29 | ``` 30 | 31 | 6. Get length and width of a rectangle using prompt. Calculate its area (area = length x width) and perimeter (perimeter = 2 x (length + width)) 32 | 7. Get radius of a circle using prompt. Calculate the area (area = pi x r x r) and circumference (c = 2 x pi x r) where pi = 3.14. 33 | 8. Calculate the slope, x-intercept and y-intercept of y = 2x -2 34 | 9. Slope is (m = y2-y1/x2-x1). Find the slope and [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance#:~:text=In%20mathematics%2C%20the%20Euclidean%20distance,being%20called%20the%20Pythagorean%20distance.) between point (2, 2) and point (6,10) 35 | 10. Compare the slopes in tasks 8 and 9. 36 | 11. Calculate the value of y (y = x^2 + 6x + 9). Try to use different x values and figure out at what x value y is going to be 0. 37 | 12. Find the length of 'python' and 'dragon' and make a falsy comparison statement. 38 | 13. Use _and_ operator to check if 'on' is found in both 'python' and 'dragon' 39 | 14. _I hope this course is not full of jargon_. Use _in_ operator to check if _jargon_ is in the sentence. 40 | 15. There is no 'on' in both dragon and python 41 | 16. Find the length of the text _python_ and convert the value to float and convert it to string 42 | 17. Even numbers are divisible by 2 and the remainder is zero. How do you check if a number is even or not using python? 43 | 18. Check if the floor division of 7 by 3 is equal to the int converted value of 2.7. 44 | 19. Check if type of '10' is equal to type of 10 45 | 20. Check if int('9.8') is equal to 10 46 | 21. Writ a script that prompts the user to enter hours and rate per hour. Calculate pay of the person? 47 | 48 | ```py 49 | Enter hours: 40 50 | Enter rate per hour: 28 51 | Your weekly earning is 1120 52 | ``` 53 | 54 | 22. Write a script that prompts the user to enter number of years. Calculate the number of seconds a person can live. Assume a person can live hundred years 55 | 56 | ```py 57 | Enter number of years you have lived: 100 58 | You have lived for 3153600000 seconds. 59 | ``` 60 | 61 | 23. Write a Python script that displays the following table 62 | 63 | ```py 64 | 1 1 1 1 1 65 | 2 1 2 4 8 66 | 3 1 3 9 27 67 | 4 1 4 16 64 68 | 5 1 5 25 125 69 | ``` 70 | -------------------------------------------------------------------------------- /Day 18/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Eighteen 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 18](#-exercises-day-18) 8 | - [Exercises: Level 1](#exercises-level-1) 9 | - [Exercises: Level 2](#exercises-level-2) 10 | - [Exercises: Level 3](#exercises-level-3) 11 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2018/Python%20Syntax/Day18%20Syntax.py) 12 | 13 | ## Objective 14 | This repository contains the solution for the Day Eighteen of the "30 Days of Python Challenge"! 15 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 16 | 17 | ## 💻 Exercises: Day 18 18 | 19 | ### Exercises: Level 1 20 | 1. What is the most frequent word in the following paragraph? 21 | ```py 22 | paragraph = 'I love teaching. If you do not love teaching what else can you love. I love Python if you do not love something which can give you all the capabilities to develop an application what else can you love. 23 | ``` 24 | 25 | ```sh 26 | [ 27 | (6, 'love'), 28 | (5, 'you'), 29 | (3, 'can'), 30 | (2, 'what'), 31 | (2, 'teaching'), 32 | (2, 'not'), 33 | (2, 'else'), 34 | (2, 'do'), 35 | (2, 'I'), 36 | (1, 'which'), 37 | (1, 'to'), 38 | (1, 'the'), 39 | (1, 'something'), 40 | (1, 'if'), 41 | (1, 'give'), 42 | (1, 'develop'), 43 | (1, 'capabilities'), 44 | (1, 'application'), 45 | (1, 'an'), 46 | (1, 'all'), 47 | (1, 'Python'), 48 | (1, 'If') 49 | ] 50 | ``` 51 | 52 | 2. The position of some particles on the horizontal x-axis are -12, -4, -3 and -1 in the negative direction, 0 at origin, 4 and 8 in the positive direction. Extract these numbers from this whole text and find the distance between the two furthest particles. 53 | 54 | ```py 55 | points = ['-1', '2', '-4', '-3', '-1', '0', '4', '8'] 56 | sorted_points = [-4, -3, -1, -1, 0, 2, 4, 8] 57 | distance = 8 -(-4) # 12 58 | ``` 59 | 60 | ### Exercises: Level 2 61 | 62 | 1. Write a pattern which identifies if a string is a valid python variable 63 | 64 | ```sh 65 | is_valid_variable('first_name') # True 66 | is_valid_variable('first-name') # False 67 | is_valid_variable('1first_name') # False 68 | is_valid_variable('firstname') # True 69 | ``` 70 | 71 | ### Exercises: Level 3 72 | 73 | 1. Clean the following text. After cleaning, count three most frequent words in the string. 74 | 75 | ```py 76 | sentence = '''%I $am@% a %tea@cher%, &and& I lo%#ve %tea@ching%;. There $is nothing; &as& mo@re rewarding as educa@ting &and& @emp%o@wering peo@ple. ;I found tea@ching m%o@re interesting tha@n any other %jo@bs. %Do@es thi%s mo@tivate yo@u to be a tea@cher!?''' 77 | 78 | print(clean_text(sentence)); 79 | I am a teacher and I love teaching There is nothing as more rewarding as educating and empowering people I found teaching more interesting than any other jobs Does this motivate you to be a teacher 80 | print(most_frequent_words(cleaned_text)) # [(3, 'I'), (2, 'teaching'), (2, 'teacher')] 81 | ``` 82 | 83 | [<< Day 17](../Day%2017/README.md) | [Day 19 >>](../Day%2019/README.md) 84 | 85 | --#### [Go to Top of Page](#objective) 86 | -------------------------------------------------------------------------------- /Day 08/Python Syntax/Day08 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Eight of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 07 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | # import the "re" module 16 | import re 17 | 18 | def main(): 19 | 20 | os.system("cls") # clear console 21 | 22 | s1 = 'Day 8 Exercise level 1' 23 | s0 = '' 24 | 25 | for i in range(20): 26 | s0 += "--" 27 | 28 | s = s0 + s1 + s0 29 | print(s) 30 | #1. Create an empty dictionary called dog 31 | print("Number 1") 32 | dog= dict() 33 | print("Dog Dict: ", dog) 34 | print("\n") 35 | 36 | #2. Add name, color, breed, legs, age to the dog dictionary 37 | print("Number 2") 38 | dog["name"] = "Cujo" 39 | dog["breed"] = "St Bernard" 40 | dog["legs"] = 4 41 | dog["age"] = 7 42 | print("Dog Dict: ", dog) 43 | print("\n") 44 | 45 | #3. Create a student dictionary and add first_name, last_name, gender, age, marital status, skills, country, city and address as keys for the dictionary 46 | print("Number 3") 47 | student_dict = {"first_name":"Harry", "last_name":"Potter", "gender":"male", "age":17, "marital_status":"Single", 48 | "skills":["wizardry","surfing"],"country":"England","city":"London","address":"100 Baker Street"} 49 | print(student_dict) 50 | print("\n") 51 | 52 | #4. Get the length of the student dictionary 53 | print("Number 4") 54 | print(len(student_dict)) 55 | print("\n") 56 | 57 | 58 | #5. Get the value of skills and check the data type, it should be a list 59 | print("Number 5") 60 | print(student_dict["skills"]) 61 | print(type(student_dict["skills"])) 62 | print("\n") 63 | 64 | 65 | #6. Modify the skills values by adding one or two skills 66 | print("Number 6") 67 | print(student_dict) 68 | student_dict["skills"]=("wizardry","surfing","quidditch","flying") 69 | print(student_dict) 70 | print("\n") 71 | 72 | #7 Get the dictionary keys as a list 73 | print("Number 7") 74 | print("Student Keys:", student_dict.keys()) 75 | print("\n") 76 | 77 | #8 Get the dictionary values as a list 78 | print("Number 8") 79 | print("Student Value:", student_dict.values()) 80 | print("\n") 81 | 82 | #9 Change the dictionary to a list of tuples using items() method 83 | print("Number 9") 84 | student_tuples = student_dict.items () 85 | print("Student Items as a Tuple:",student_tuples) 86 | print("\n") 87 | 88 | #10 Delete one of the items in the dictionary 89 | print("Number 10") 90 | print("Student Items before deletion",student_dict) 91 | del student_dict["marital_status"] 92 | print("Student Items before deletion",student_dict) 93 | print("\n") 94 | 95 | #11 Delete one of the dictionaries 96 | print("Number 11") 97 | del student_dict 98 | try: 99 | print(f"Student Dict",student_dict) 100 | except NameError as e: 101 | print("Dict does not exist") 102 | print(e) 103 | print("\n") 104 | 105 | 106 | if __name__ == "__main__": 107 | main() 108 | -------------------------------------------------------------------------------- /Day 04/Day04 Solution.txt: -------------------------------------------------------------------------------- 1 | umber 1 2 | Thirty Days Of Python 3 | 4 | 5 | Number 2 6 | Coding For All 7 | 8 | 9 | Number 3 10 | 11 | 12 | Number 4 13 | Coding For All 14 | 15 | 16 | Number 5 17 | 14 18 | 19 | Number 6 20 | CODING FOR ALL 21 | 22 | Number 7 23 | coding for all 24 | 25 | 26 | Number 8 27 | Capitalize(): Coding for all 28 | Title(): Coding For All 29 | Swapcase 1(): cODING fOR aLL 30 | Swapcase 2(): Coding For All 31 | 32 | Number 9 33 | Coding 34 | 35 | 36 | Number 10 37 | 0 38 | 39 | Number 11 40 | Python For All 41 | 42 | Number 12 43 | Python for All 44 | 45 | Number 13 46 | ['Coding', 'For', 'All'] 47 | 48 | Number 14 49 | ['Facebook', ' Google', ' Microsoft', ' Apple', ' IBM', ' Oracle', ' Amazon'] 50 | 51 | Number 15 52 | Character at Index 0: C 53 | 54 | 55 | Number 16 56 | Character at Index last: l 57 | 58 | 59 | Number 17 60 | Character at Index 10: 61 | 62 | Number 18 63 | Python for Everyone 64 | Acronym: PfE 65 | 66 | 67 | Number 19 68 | Coding For All 69 | Acronym: CFA 70 | 71 | Number 20 72 | 1 73 | 74 | 75 | Number 21 76 | 8 77 | 78 | 79 | Number 22 80 | Last occurrence of the word 'l':14 81 | 82 | 83 | Number 23 84 | first occurrence of the word 'because': 32 85 | 86 | Number 24 87 | last occurrence of the word 'because': 48 88 | 89 | Number 25 90 | Original Word: You cannot end a sentence with because because because is a conjunction 91 | Split List before spaces ['You cannot end a sentence with ', ' ', ' ', ' is a conjunction'] 92 | Split List after spaces ['You cannot end a sentence with ', ' is a conjunction'] 93 | Final word: You cannot end a sentence with is a conjunction 94 | 95 | 96 | Number 26 97 | first index of because (31, 38) 98 | 99 | Number 27 100 | Final word: You cannot end a sentence with is a conjunction 101 | 102 | 103 | 104 | 105 | 106 | Number 28 107 | 'Coding For All' Starts with 'Codng'? T/F: True 108 | 109 | 110 | Number 29 111 | 'Coding For All' Ends with 'Codng'? T/F: False 112 | 113 | 114 | Number 30 115 | Original Word: Coding For All 116 | :Striped String: Coding For All 117 | 118 | 119 | Number 31 120 | is 30DaysOfPython a valid identifier?T/F: False 121 | is thirty_days_of_python a valid identifier?T/F: True 122 | 123 | 124 | Number 32 125 | Django# Flask# Bottle# Pyramid# Falcon 126 | 127 | 128 | Number 33 129 | I am enjoying this challenge 130 | I 131 | am 132 | enjoying 133 | this 134 | challenge 135 | 136 | 137 | I just wonder what is next 138 | I 139 | just 140 | wonder 141 | what 142 | is 143 | next 144 | 145 | 146 | I just wonder what is next 147 | I 148 | just 149 | wonder 150 | what 151 | is 152 | next 153 | 154 | Number 34 155 | My Dict {'Name': 'Asabeneh', 'Age': 250, 'Country': 'Finland', 'City': 'Helsinki'} 156 | Name Age Country City 157 | Asabeneh 250 Finland Helsinki 158 | 159 | Number 35 160 | radius = 10 161 | area = 3.14 * radius ** 2 162 | The area of a circle with radius 10 is 314 meters square 163 | 164 | Number 36 165 | 8 + 6 = 14 166 | 8 - 6 = 2 167 | 8 * 6 = 48 168 | 8 / 6 = 1.33 169 | 8 % 6 = 2 170 | 8 // 6 = 1 171 | 8 ** 6 = 262,144 172 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /Day 05/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Five 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 5](#exercises-day-5) 8 | - [Exercise: Level 1](#exercise-level-1) 9 | - [Exercise: Level 2](#exercise-level-2) 10 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2005/Python%20Syntax/Day05%20Syntax.py) 11 | 12 | ## Objective 13 | This repository contains the solution for the Day Five of the "30 Days of Python Challenge"! 14 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 15 | 16 | 17 | ## 💻Exercises: Day 5 18 | 19 | ### Exercise: Level 1 20 | 21 | 1. Declare an empty list 22 | 2. Declare a list with more than 5 items 23 | 3. Find the length of your list 24 | 4. Get the first item, the middle item and the last item of the list 25 | 5. Declare a list called mixed_data_types, put your(name, age, height, marital status, address) 26 | 6. Declare a list variable named it_companies and assign initial values Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon. 27 | 7. Print the list using _print()_ 28 | 8. Print the number of companies in the list 29 | 9. Print the first, middle and last company 30 | 10. Print the list after modifying one of the companies 31 | 11. Add an IT company to it_companies 32 | 12. Insert an IT company in the middle of the companies list 33 | 13. Change one of the it_companies names to uppercase (IBM excluded!) 34 | 14. Join the it_companies with a string '#;  ' 35 | 15. Check if a certain company exists in the it_companies list. 36 | 16. Sort the list using sort() method 37 | 17. Reverse the list in descending order using reverse() method 38 | 18. Slice out the first 3 companies from the list 39 | 19. Slice out the last 3 companies from the list 40 | 20. Slice out the middle IT company or companies from the list 41 | 21. Remove the first IT company from the list 42 | 22. Remove the middle IT company or companies from the list 43 | 23. Remove the last IT company from the list 44 | 24. Remove all IT companies from the list 45 | 25. Destroy the IT companies list 46 | 26. Join the following lists: 47 | 48 | ```py 49 | front_end = ['HTML', 'CSS', 'JS', 'React', 'Redux'] 50 | back_end = ['Node','Express', 'MongoDB'] 51 | ``` 52 | 53 | 27. After joining the lists in question 26. Copy the joined list and assign it to a variable full_stack. Then insert Python and SQL after Redux. 54 | 55 | ### Exercise: Level 2 56 | 57 | 1. The following is a list of 10 students ages: 58 | 59 | ```sh 60 | ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24] 61 | ``` 62 | 63 | - Sort the list and find the min and max age 64 | - Add the min age and the max age again to the list 65 | - Find the median age (one middle item or two middle items divided by two) 66 | - Find the average age (sum of all items divided by their number ) 67 | - Find the range of the ages (max minus min) 68 | - Compare the value of (min - average) and (max - average), use _abs()_ method 69 | 70 | 1. Find the middle country(ies) in the [countries list](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2005/countries.txt) 71 | 1. Divide the countries list into two equal lists if it is even if not one more country for the first half. 72 | 1. ['China', 'Russia', 'USA', 'Finland', 'Sweden', 'Norway', 'Denmark']. Unpack the first three countries and the rest as scandic countries. 73 | 74 | #### [Go to Top of Page](#-lets-go--) 75 | -------------------------------------------------------------------------------- /Day 14/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Fourteen 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 14](#-exercises-day-14) 8 | - [Exercises: Level 1](#exercises-level-1) 9 | - [Exercises: Level 2](#exercises-level-2) 10 | - [Exercises: Level 3](#exercises-level-3) 11 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2014/Python%20Syntax/Day14%20Syntax.py) 12 | 13 | ## Objective 14 | This repository contains the solution for the Day Fourteen of the "30 Days of Python Challenge"! 15 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 16 | 17 | ## 💻 Exercises: Day 14 18 | 19 | ```py 20 | countries = ['Estonia', 'Finland', 'Sweden', 'Denmark', 'Norway', 'Iceland'] 21 | names = ['Asabeneh', 'Lidiya', 'Ermias', 'Abraham'] 22 | numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 23 | ``` 24 | 25 | ### Exercises: Level 1 26 | 27 | 1. Explain the difference between map, filter, and reduce. 28 | 2. Explain the difference between higher order function, closure and decorator 29 | 3. Define a call function before map, filter or reduce, see examples. 30 | 4. Use for loop to print each country in the countries list. 31 | 5. Use for to print each name in the names list. 32 | 6. Use for to print each number in the numbers list. 33 | 34 | ### Exercises: Level 2 35 | 36 | 1. Use map to create a new list by changing each country to uppercase in the countries list 37 | 1. Use map to create a new list by changing each number to its square in the numbers list 38 | 1. Use map to change each name to uppercase in the names list 39 | 1. Use filter to filter out countries containing 'land'. 40 | 1. Use filter to filter out countries having exactly six characters. 41 | 1. Use filter to filter out countries containing six letters and more in the country list. 42 | 1. Use filter to filter out countries starting with an 'E' 43 | 1. Chain two or more list iterators (eg. arr.map(callback).filter(callback).reduce(callback)) 44 | 1. Declare a function called get_string_lists which takes a list as a parameter and then returns a list containing only string items. 45 | 1. Use reduce to sum all the numbers in the numbers list. 46 | 1. Use reduce to concatenate all the countries and to produce this sentence: Estonia, Finland, Sweden, Denmark, Norway, and Iceland are north European countries 47 | 1. Declare a function called categorize_countries that returns a list of countries with some common pattern (you can find the [countries list](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/countries.py) in this repository as countries.js(eg 'land', 'ia', 'island', 'stan')). 48 | 1. Create a function returning a dictionary, where keys stand for starting letters of countries and values are the number of country names starting with that letter. 49 | 2. Declare a get_first_ten_countries function - it returns a list of first ten countries from the countries.js list in the data folder. 50 | 1. Declare a get_last_ten_countries function that returns the last ten countries in the countries list. 51 | 52 | ### Exercises: Level 3 53 | 54 | 1. Use the countries_data.py file and follow the tasks below: 55 | - Sort countries by name, by capital, by population 56 | - Sort out the ten most spoken languages by location. 57 | - Sort out the ten most populated countries. 58 | 59 | [<< Day 13](../Day%2013/README.md) | [Day 15 >>](../Day%2014/README.md) 60 | 61 | 62 | --#### [Go to Top of Page](#objective) 63 | -------------------------------------------------------------------------------- /Day 10/Day10 Solution.txt: -------------------------------------------------------------------------------- 1 | ----------------------------------------Day 10 Exercise level 1---------------------------------------- 2 | Number 1 3 | Using For Loop from 0 to 10 4 | 0 5 | 1 6 | 2 7 | 3 8 | 4 9 | 5 10 | 6 11 | 7 12 | 8 13 | 9 14 | 10 15 | ---------------------------------------- 16 | Using While Loop from 0 to 10 17 | 0 18 | 1 19 | 2 20 | 3 21 | 4 22 | 5 23 | 6 24 | 7 25 | 8 26 | 9 27 | 10 28 | 29 | Number 2 30 | Using For Loop from 10 to 0 31 | 10 32 | 9 33 | 8 34 | 7 35 | 6 36 | 5 37 | 4 38 | 3 39 | 2 40 | 1 41 | 0 42 | ---------------------------------------- 43 | Using While Loop from 10 to 0 44 | 10 45 | 9 46 | 8 47 | 7 48 | 6 49 | 5 50 | 4 51 | 3 52 | 2 53 | 1 54 | 0 55 | 56 | 57 | Number 3 -method 1 using multiplier 58 | # 59 | ## 60 | ### 61 | #### 62 | ##### 63 | ###### 64 | ####### 65 | 66 | 67 | Number 3B - #method 2 using nested if 68 | # 69 | ## 70 | ### 71 | #### 72 | ##### 73 | ###### 74 | ####### 75 | 76 | Number 4 77 | ######## 78 | ######## 79 | ######## 80 | ######## 81 | ######## 82 | ######## 83 | ######## 84 | ######## 85 | 86 | 87 | Number 5 88 | 0 * 0 = 0 89 | 1 * 1 = 1 90 | 2 * 2 = 4 91 | 3 * 3 = 9 92 | 4 * 4 = 16 93 | 5 * 5 = 25 94 | 6 * 6 = 36 95 | 7 * 7 = 49 96 | 8 * 8 = 64 97 | 9 * 9 = 81 98 | 10 * 10 = 100 99 | 100 | Number 6 101 | Python 102 | Numpy 103 | Pandas 104 | Django 105 | Flask 106 | 107 | Number 7 108 | Evenlist: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100] 109 | 110 | 111 | Number 8 112 | Oddlist: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99] 113 | 114 | 115 | ----------------------------------------Day 10 Exercise level 2---------------------------------------- 116 | Number 1 117 | The sum of all numbers is {sum100}. 118 | 119 | 120 | Number 2 121 | The sum of all evens is 2550. And the sum of all odds is 2500. 122 | 123 | ----------------------------------------Day 10 Exercise level 3---------------------------------------- 124 | Number 1 125 | There are 11 Countries with 'land' in them:, ['Finland', 'Iceland', 'Ireland', 'Marshall Islands', 'Netherlands', 'New Zealand', 'Poland', 'Solomon Islands', 'Swaziland', 'Switzerland', 'Thailand']. 126 | 127 | Number 2 128 | lemon 129 | mango 130 | orange 131 | banana 132 | 133 | 3. Top 10 populated countries in the Data 134 | Country: China Population 1,377,422,166 135 | Country: India Population 1,295,210,000 136 | Country: United States of America Population 323,947,000 137 | Country: Indonesia Population 258,705,000 138 | Country: Brazil Population 206,135,893 139 | Country: Pakistan Population 194,125,062 140 | Country: Nigeria Population 186,988,000 141 | Country: Bangladesh Population 161,006,790 142 | Country: Russian Federation Population 146,599,183 143 | Country: Japan Population 126,960,000 144 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python 4 | 5 | This repository contains the solution for the 30 Days of Python Challenge! 6 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 7 | 8 | 9 | ## 📚 Table of Contents 10 | - [Getting Ready](#--getting-ready) 11 | - [Day #01: Introduction](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2001) 12 | - [Day #02: Variables, Built-in Functions](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2002) 13 | - [Day #03: Operators](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day03) 14 | - [Day #04: Strings](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2004) 15 | - [Day #05: Lists](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2005) 16 | - [Day #06: Tuples](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2006) 17 | - [Day #07: Sets](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2007) 18 | - [Day #08: Dictionaries](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2008) 19 | - [Day #09: Conditionals](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2009) 20 | - [Day #10: Loops](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2010) 21 | - [Day #11: Functions](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2011) 22 | - [Day #12: Modules](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2012) 23 | - [Day #13: List Comprehension](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2013) 24 | - [Day #14: Higher Order Functions](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2014) 25 | - [Day #15: Python Type Errors](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2015) 26 | - [Day #16: Python Date time](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2016) 27 | - [Day #17: Exception Handling](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2017) 28 | - [Day #18: Regular Expressions](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2018) 29 | - [Day #19: File Handling](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2019) 30 | - [Day #20: Python Package Manager](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2020) 31 | - [Day #21: Classes and Objects](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2021) 32 | - [Day #22: Web Scraping](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2022) 33 | - [Day #23: Virtual Environment](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2023) 34 | - [Day #24: Statistics](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2024) 35 | - [Day #25: Pandas](https://github.com/zidude1234/30_Days_of_Python/tree/main/Day%2025) 36 | - [Day #26: Python web](#Python-web) 37 | - [Day #27: Python with MongoDB](#Python-with-MongoDB) 38 | - [Day #28: API](#API) 39 | - [Day #29: Building API](#Building-API) 40 | - [Day #30: Conclusions](#Conclusions) 41 | - [Credits and Support to Author](#Credits) 42 | 43 | 44 | ## 🎬 Getting Ready 45 | 1. To run a python script you need to [Install Python](https://www.python.org/). 46 | 2. Install a Code Editor of choice 47 | 3. More Information at [Asabeneh's Guide](https://github.com/Asabeneh/30-Days-Of-Python#environment-setup) 48 | 49 | 50 | ## 👍 Credits 51 | Credit to Asabaneh 52 |
53 | Support the author to create more educational materials
54 | Paypal Logo 55 |
56 | -------------------------------------------------------------------------------- /Day 18/Python Syntax/Day18 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Eighteen of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 18 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | # import the "re" module 16 | import re 17 | import collections 18 | import datetime 19 | 20 | def main(): 21 | os.system("cls") # clear console 22 | 23 | def p(num): 24 | print(f"Number {num}") 25 | 26 | def pn(num = 1): 27 | print(f"\n" * num) 28 | 29 | def bannergreeting(day_name,exercise_name): 30 | daybanner = f'Exercise {day_name} ' 31 | exercisebanner = f'Level {exercise_name} ' 32 | front_end = f'--' * 20 33 | return combinebanners(front_end,daybanner,exercisebanner) 34 | 35 | def combinebanners(s0,s1,s2): 36 | return s0 + s1 + s2 + s0 37 | 38 | banner = bannergreeting 39 | print(banner(18,1)) 40 | 41 | #1 What is the most frequent word in the following paragraph? 42 | paragraph = '''I love teaching. If you do not love teaching what else can you love. 43 | I love Python if you do not love something which can give you all the capabilities to develop an application what else can you love.''' 44 | 45 | split_words = re.split('\s+|\.',paragraph) 46 | split_words = list(filter(None,split_words)) #because of the space filtered out 47 | print("Split Words:", split_words) 48 | 49 | words_collection = collections.Counter(split_words) 50 | print(words_collection) 51 | pn() 52 | 53 | word_tp = words_collection.items() 54 | word_tuple = [(b,a) for (a,b) in word_tp] 55 | word2 = sorted(word_tuple,key = lambda k: (k[0],k[1]), reverse=True) 56 | print("Final sorted Tuple:",word2) 57 | pn() 58 | 59 | #2 Extract these numbers from this whole text and find the distance between the two furthest particles 60 | p(2) 61 | points = ['-1', '2', '-4', '-3', '-1', '0', '4', '8'] 62 | s1 = sorted(points,key = lambda k:int(k)) # ['-4', '-3', '-1', '-1', '0', '2', '4', '8'] 63 | sorted_points = [int(i) for i in s1] 64 | print("original list:", points) 65 | print("sorted list:", sorted_points) 66 | print(f'distance = {max(sorted_points)} - {min(sorted_points)} = {max(sorted_points)-min(sorted_points)}') 67 | 68 | print(banner(18,2)) 69 | #1. Write a pattern which identifies if a string is a valid python variable 70 | p(1) 71 | stringvar = ['first_name','first-name','1first_name','firstname'] 72 | regexpattern_v = '^[A-Za-z_]\w*$' 73 | for i in stringvar: 74 | if re.match(regexpattern_v,i): 75 | print(i,"True") 76 | else: 77 | print(i,"False") 78 | 79 | print(banner(18,3)) 80 | #1. Clean the following text. After cleaning, count three most frequent words in the string. 81 | p(1) 82 | sentence = '''%I $am@% a %tea@cher%, &and& I lo%#ve %tea@ching%;. There $is nothing; &as& mo@re rewarding as educa@ting &and& @emp%o@wering peo@ple. ;I found tea@ching m%o@re interesting tha@n any other %jo@bs. %Do@es thi%s mo@tivate yo@u to be a tea@cher!?''' 83 | 84 | replace_pattern = '@|%|\$|&|;|#|!' 85 | 86 | def clean_text(sentence): 87 | return re.sub(replace_pattern, '', sentence) 88 | 89 | def most_frequent_words(sentence): 90 | seperate_words = list(filter(None,re.split('\s+|\.',sentence))) #this includes space with it. 91 | words_group = collections.Counter(seperate_words) 92 | w_tp = words_group.items() 93 | w_tp2 = [(b,a) for (a,b) in w_tp] 94 | w_tuple = sorted(w_tp2,key = lambda k:k[0],reverse=True) 95 | return w_tuple[0:3] 96 | 97 | print(clean_text(sentence)) 98 | a = clean_text(sentence) 99 | print(most_frequent_words(a)) 100 | 101 | 102 | 103 | if __name__ == "__main__": 104 | main() 105 | -------------------------------------------------------------------------------- /Day 03/Day03 Solution.txt: -------------------------------------------------------------------------------- 1 | Number 4 2 | Enter the base: 3 | 20 4 | Enter the height: 5 | 10 6 | The area of the triangle is 100 7 | 8 | 9 | Number 5 10 | Enter side a: 11 | 4 12 | Enter side b: 13 | 7 14 | Enter side c: 15 | 09 16 | The perimeter of the triangle is 20 17 | 18 | 19 | Number 6 20 | Enter the rectangle length: 21 | 4 22 | Enter the rectangle width: 23 | 5 24 | The area of the rectangle is 20 25 | The perimeter of the rectangle is 18 26 | 27 | 28 | Number 7 29 | Enter the radius of the circle: 30 | 4 31 | The area of the circle is 50.27 32 | The circumference of the circle is 25.13 33 | 34 | 35 | Number 8 36 | For the line equation y = 2x - 2 37 | The slope of the equation 2 38 | X intercept 1.0 39 | Y intercept -2 40 | 41 | 42 | Number 9 43 | The Slope of points(2, 2) and (6, 10) equals 2.00 44 | The Euclidian distance between points(2, 2) and (6, 10) equals 8.94 45 | 46 | Number 4 47 | Enter the base: 48 | 20 49 | Enter the height: 50 | 10 51 | The area of the triangle is 100 52 | 53 | 54 | Number 5 55 | Enter side a: 56 | 4 57 | Enter side b: 58 | 6 59 | Enter side c: 60 | 7 61 | The perimeter of the triangle is 17 62 | 63 | 64 | Number 6 65 | Enter the rectangle length: 66 | 5 67 | Enter the rectangle width: 68 | 3 69 | The area of the rectangle is 15 70 | The perimeter of the rectangle is 16 71 | 72 | 73 | Number 7 74 | Enter the radius of the circle: 75 | 5 76 | The area of the circle is 78.54 77 | The circumference of the circle is 31.42 78 | 79 | 80 | Number 8 81 | For the line equation y = 2x - 2 82 | The slope of the equation 2 83 | X intercept 1.0 84 | Y intercept -2 85 | 86 | 87 | Number 9 88 | The Slope of points(2, 2) and (6, 10) equals 2.00 89 | The Euclidian distance between points(2, 2) and (6, 10) equals 8.94 90 | 91 | 92 | Number 10 93 | The slopes are equal 94 | 95 | Number 11 96 | Enter x value for the quadratic equation (y = x^2 + 6x + 9) 97 | z 98 | Enter a valid integer 99 | Enter x value for the quadratic equation (y = x^2 + 6x + 9) 100 | 5 101 | The value of y is 64 102 | The next step is to iterate to find the x value where y value is zero 103 | Enter x value for the quadratic equation (y = x^2 + 6x + 9) 104 | -1 105 | The value of y is 4, this is not equal to zero 106 | Enter x value for the quadratic equation (y = x^2 + 6x + 9) 107 | -8 108 | The value of y is 25, this is not equal to zero 109 | Enter x value for the quadratic equation (y = x^2 + 6x + 9) 110 | -3 111 | The value at which y is zero is -3 112 | 113 | 114 | Number 12 115 | True 116 | 117 | Number 13 118 | "on" appears in both python and dragon 119 | 120 | Number 14 121 | jargon found in "I hope this course is not full of jargon" 122 | 123 | Number 15 124 | 'on' found in "python and dragon 125 | 126 | Number 16 127 | length of 'python' is: 6 128 | In float length of 'python' is: 6.0 129 | In string length of 'python' is: 6.0 130 | 131 | Number 17 132 | 1 is odd 133 | 2 is even 134 | 3 is odd 135 | 4 is even 136 | 5 is odd 137 | 6 is even 138 | 7 is odd 139 | 8 is even 140 | 9 is odd 141 | 10 is even 142 | 143 | 144 | Number 18 145 | floor division of 7 by 3 is equal to the int converted value of 2.7 146 | 147 | Number 19 148 | Types "10" and 10 are not equal 149 | 150 | Number 20 151 | Decimal strings cannot be made into int 152 | 'int('9.8')' is not equal to {10} 153 | 154 | Number 21 155 | Enter hours: 156 | 40 157 | Enter rate per hour: 158 | 30 159 | Your weekly earning is 1200 160 | 161 | 162 | Number 22 163 | Enter number of years you have lived: 164 | 100 165 | You have lived for 3153600000 seconds. 166 | 167 | 168 | Number 23 169 | [1, 1, 1, 1, 1] 170 | [2, 1, 2, 4, 8] 171 | [3, 1, 3, 9, 27] 172 | [4, 1, 4, 16, 64] 173 | [5, 1, 5, 25, 125] 174 | -------------------------------------------------------------------------------- /Day 11/Day11 Solution.txt: -------------------------------------------------------------------------------- 1 | ----------------------------------------Day 11 Exercise level 1---------------------------------------- 2 | Number 1 3 | Enter number one: 4 | 5 5 | Enter number two: 6 | 7 7 | The sum of 5 and 7 is 12 8 | 9 | 10 | Number 2 11 | Enter radius of circle: 12 | 4 13 | Enter dimension of circle(cm/m/km): 14 | m 15 | The area of a circle with radius 4 m is 50.27 m² 16 | 17 | Number 3 18 | The sum of numbers (8, 3, 5, 7, 'j') is 23 19 | The sum of numbers ('gh', 5, 4, 32, 40, 68, 95) is 244 20 | In this list "[7]" is not a valid number. replaced with zero 21 | The sum of numbers (5, 24, 7, 0, 3, 5, 7, 6, '[7]') is 57 22 | The sum of numbers (7, 5, 'j') is 12 23 | 24 | Number 4 25 | The temperature of 1000 ℃ is 1,832 ℉ 26 | 27 | Number 5 28 | ('January',) 29 | The month of January is "Winter" 30 | 31 | ('January', 'April', 'Gregorian') 32 | The month of January is "Winter" 33 | The month of April is "Spring" 34 | The month of Gregorian does not exist! 35 | 36 | Number 6 37 | Enter the x-coefficient: 38 | 6 39 | Enter the y-intercept: 40 | 4 41 | The slope of the equation y=6x + 4 is 6 42 | 43 | Number 7 44 | Roots of 1x² + 7x + 10 are: 45 | x₁ = -2.0 46 | x₂ = -5.0 47 | 48 | Number 8 49 | Item 1: 8 50 | Item 2: 3 51 | Item 3: 5 52 | Item 4: 7 53 | Item 5: j 54 | 55 | Number 9 56 | The reverse of the list [8, 3, 5, 7, 'j'] is ['j', 7, 5, 3, 8]" 57 | 58 | Number 10 59 | The capitalised form of the list ['bETTer beliEVE', 'cOLD COLd HeART', 'pEACHES in Georgia', 'sACrifICe'] is 60 | ['Better Believe', 'Cold Cold Heart', 'Peaches In Georgia', 'Sacrifice'] 61 | 62 | 63 | Number 11 64 | ['Better Believe', 'Cold Cold Heart', 'Peaches In Georgia', 'Sacrifice'] 65 | ['Better Believe', 'Cold Cold Heart', 'Peaches In Georgia', 'Sacrifice', 'Take My Breath'] 66 | 67 | 68 | Number 12 69 | ['Potato', 'Tomato', 'Milk', 'Meat'] 70 | [2, 7, 9, 5] 71 | Item 10 not in list 72 | [2, 7, 9, 5] 73 | 74 | Number 13 75 | 15 76 | 55 77 | 5050 78 | 79 | Number 14 80 | 9 81 | 25 82 | 2500 83 | 84 | 85 | Number 15 86 | 6 87 | 30 88 | 2550 89 | 90 | ----------------------------------------Day 11 Exercise level 2---------------------------------------- 91 | Number 1 92 | The number of odds are 50 93 | The number of evens are 51 94 | 95 | Number 2 96 | 120 97 | 98 | Number 3 99 | ['', [], 0, 25, ['5', 6, 9]] 100 | [False, False, False, True, True] 101 | 102 | 103 | Number 4 104 | For the list of numbers [4, 3, 5, 8] the statistics are as follows: 105 | Sum: 20 106 | Mean: 5.0 107 | Median: 4.5 108 | Mode: 4 109 | Range: 5 110 | Variance: 3.5 111 | Standard Deviation: 1.8708286933869707 112 | 113 | For the list of numbers [4, 3, 5, 8, 5] the statistics are as follows: 114 | Sum: 25 115 | Mean: 5.0 116 | Median: 5 117 | Mode: 5 118 | Range: 5 119 | Variance: 2.8 120 | Standard Deviation: 1.6733200530681511 121 | 122 | 123 | ----------------------------------------Day 11 Exercise level 3---------------------------------------- 124 | Number 1 125 | 121 is not a prime number, factor is 11 126 | 127 | 128 | Number 2 129 | List [4, 3, 5, 8, 5] is not unique. 130 | 5 - first item not unique 131 | List ['1', 2, 1, 'The dog flew over the moon', 7, 'The dog flew over the moon'] is not unique. 132 | The dog flew over the moon - first item not unique 133 | [4, 3, 5, 8, 'i'] is a unique list 134 | 135 | Number 3 136 | List [4, 3, 5, 8, 'i'] does not have same type. 137 | i - first type not same type 138 | [4, 3, 5, 8, 5] is the same data type 139 | 140 | Number 4 141 | 142 | Enter desired variable name: 143 | 123 144 | 123 is not a valid variable name. 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /Day 05/countries.txt: -------------------------------------------------------------------------------- 1 | countries = [ 2 | 'Afghanistan', 3 | 'Albania', 4 | 'Algeria', 5 | 'Andorra', 6 | 'Angola', 7 | 'Antigua and Barbuda', 8 | 'Argentina', 9 | 'Armenia', 10 | 'Australia', 11 | 'Austria', 12 | 'Azerbaijan', 13 | 'Bahamas', 14 | 'Bahrain', 15 | 'Bangladesh', 16 | 'Barbados', 17 | 'Belarus', 18 | 'Belgium', 19 | 'Belize', 20 | 'Benin', 21 | 'Bhutan', 22 | 'Bolivia', 23 | 'Bosnia and Herzegovina', 24 | 'Botswana', 25 | 'Brazil', 26 | 'Brunei', 27 | 'Bulgaria', 28 | 'Burkina Faso', 29 | 'Burundi', 30 | 'Cambodia', 31 | 'Cameroon', 32 | 'Canada', 33 | 'Cape Verde', 34 | 'Central African Republic', 35 | 'Chad', 36 | 'Chile', 37 | 'China', 38 | 'Colombi', 39 | 'Comoros', 40 | 'Congo (Brazzaville)', 41 | 'Congo', 42 | 'Costa Rica', 43 | "Cote d'Ivoire", 44 | 'Croatia', 45 | 'Cuba', 46 | 'Cyprus', 47 | 'Czech Republic', 48 | 'Denmark', 49 | 'Djibouti', 50 | 'Dominica', 51 | 'Dominican Republic', 52 | 'East Timor (Timor Timur)', 53 | 'Ecuador', 54 | 'Egypt', 55 | 'El Salvador', 56 | 'Equatorial Guinea', 57 | 'Eritrea', 58 | 'Estonia', 59 | 'Ethiopia', 60 | 'Fiji', 61 | 'Finland', 62 | 'France', 63 | 'Gabon', 64 | 'Gambia, The', 65 | 'Georgia', 66 | 'Germany', 67 | 'Ghana', 68 | 'Greece', 69 | 'Grenada', 70 | 'Guatemala', 71 | 'Guinea', 72 | 'Guinea-Bissau', 73 | 'Guyana', 74 | 'Haiti', 75 | 'Honduras', 76 | 'Hungary', 77 | 'Iceland', 78 | 'India', 79 | 'Indonesia', 80 | 'Iran', 81 | 'Iraq', 82 | 'Ireland', 83 | 'Israel', 84 | 'Italy', 85 | 'Jamaica', 86 | 'Japan', 87 | 'Jordan', 88 | 'Kazakhstan', 89 | 'Kenya', 90 | 'Kiribati', 91 | 'Korea, North', 92 | 'Korea, South', 93 | 'Kuwait', 94 | 'Kyrgyzstan', 95 | 'Laos', 96 | 'Latvia', 97 | 'Lebanon', 98 | 'Lesotho', 99 | 'Liberia', 100 | 'Libya', 101 | 'Liechtenstein', 102 | 'Lithuania', 103 | 'Luxembourg', 104 | 'Macedonia', 105 | 'Madagascar', 106 | 'Malawi', 107 | 'Malaysia', 108 | 'Maldives', 109 | 'Mali', 110 | 'Malta', 111 | 'Marshall Islands', 112 | 'Mauritania', 113 | 'Mauritius', 114 | 'Mexico', 115 | 'Micronesia', 116 | 'Moldova', 117 | 'Monaco', 118 | 'Mongolia', 119 | 'Morocco', 120 | 'Mozambique', 121 | 'Myanmar', 122 | 'Namibia', 123 | 'Nauru', 124 | 'Nepal', 125 | 'Netherlands', 126 | 'New Zealand', 127 | 'Nicaragua', 128 | 'Niger', 129 | 'Nigeria', 130 | 'Norway', 131 | 'Oman', 132 | 'Pakistan', 133 | 'Palau', 134 | 'Panama', 135 | 'Papua New Guinea', 136 | 'Paraguay', 137 | 'Peru', 138 | 'Philippines', 139 | 'Poland', 140 | 'Portugal', 141 | 'Qatar', 142 | 'Romania', 143 | 'Russia', 144 | 'Rwanda', 145 | 'Saint Kitts and Nevis', 146 | 'Saint Lucia', 147 | 'Saint Vincent', 148 | 'Samoa', 149 | 'San Marino', 150 | 'Sao Tome and Principe', 151 | 'Saudi Arabia', 152 | 'Senegal', 153 | 'Serbia and Montenegro', 154 | 'Seychelles', 155 | 'Sierra Leone', 156 | 'Singapore', 157 | 'Slovakia', 158 | 'Slovenia', 159 | 'Solomon Islands', 160 | 'Somalia', 161 | 'South Africa', 162 | 'Spain', 163 | 'Sri Lanka', 164 | 'Sudan', 165 | 'Suriname', 166 | 'Swaziland', 167 | 'Sweden', 168 | 'Switzerland', 169 | 'Syria', 170 | 'Taiwan', 171 | 'Tajikistan', 172 | 'Tanzania', 173 | 'Thailand', 174 | 'Togo', 175 | 'Tonga', 176 | 'Trinidad and Tobago', 177 | 'Tunisia', 178 | 'Turkey', 179 | 'Turkmenistan', 180 | 'Tuvalu', 181 | 'Uganda', 182 | 'Ukraine', 183 | 'United Arab Emirates', 184 | 'United Kingdom', 185 | 'United States', 186 | 'Uruguay', 187 | 'Uzbekistan', 188 | 'Vanuatu', 189 | 'Vatican City', 190 | 'Venezuela', 191 | 'Vietnam', 192 | 'Yemen', 193 | 'Zambia', 194 | 'Zimbabwe', 195 | ]; -------------------------------------------------------------------------------- /Day 09/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Nine 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 9](#-exercises-day-9) 8 | - [Exercise: Level 1](#exercises-level-1) 9 | - [Exercise: Level 2](#exercises-level-2) 10 | - [Exercise: Level 3](#exercises-level-3) 11 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2009/Python%20Syntax/Day09%20Syntax.py) 12 | 13 | ## Objective 14 | This repository contains the solution for the Day Nine of the "30 Days of Python Challenge"! 15 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 16 | 17 | 18 | ## 💻 Exercises: Day 9 19 | 20 | ### Exercises: Level 1 21 | 22 | 1. Get user input using input(“Enter your age: ”). If user is 18 or older, give feedback: You are old enough to drive. If below 18 give feedback to wait for the missing amount of years. Output: 23 | ```sh 24 | Enter your age: 30 25 | You are old enough to learn to drive. 26 | Output: 27 | Enter your age: 15 28 | You need 3 more years to learn to drive. 29 | ``` 30 | 2. Compare the values of my_age and your_age using if … else. Who is older (me or you)? Use input(“Enter your age: ”) to get the age as input. You can use a nested condition to print 'year' for 1 year difference in age, 'years' for bigger differences, and a custom text if my_age = your_age. Output: 31 | ```sh 32 | Enter your age: 30 33 | You are 5 years older than me. 34 | ``` 35 | 3. Get two numbers from the user using input prompt. If a is greater than b return a is greater than b, if a is less b return a is smaller than b, else a is equal to b. Output: 36 | 37 | ```sh 38 | Enter number one: 4 39 | Enter number two: 3 40 | 4 is greater than 3 41 | ``` 42 | 43 | ### Exercises: Level 2 44 | 45 | 1. Write a code which gives grade to students according to theirs scores: 46 | 47 | ```sh 48 | 80-100, A 49 | 70-89, B 50 | 60-69, C 51 | 50-59, D 52 | 0-49, F 53 | ``` 54 | 1. Check if the season is Autumn, Winter, Spring or Summer. If the user input is: 55 | September, October or November, the season is Autumn. 56 | December, January or February, the season is Winter. 57 | March, April or May, the season is Spring 58 | June, July or August, the season is Summer 59 | 2. The following list contains some fruits: 60 | ```sh 61 | fruits = ['banana', 'orange', 'mango', 'lemon'] 62 | ``` 63 | If a fruit doesn't exist in the list add the fruit to the list and print the modified list. If the fruit exists print('That fruit already exist in the list') 64 | 65 | ### Exercises: Level 3 66 | 67 | 1. Here we have a person dictionary. Feel free to modify it! 68 | 69 | ```py 70 | person={ 71 | 'first_name': 'Asabeneh', 72 | 'last_name': 'Yetayeh', 73 | 'age': 250, 74 | 'country': 'Finland', 75 | 'is_marred': True, 76 | 'skills': ['JavaScript', 'React', 'Node', 'MongoDB', 'Python'], 77 | 'address': { 78 | 'street': 'Space street', 79 | 'zipcode': '02210' 80 | } 81 | } 82 | ``` 83 | 84 | * Check if the person dictionary has skills key, if so print out the middle skill in the skills list. 85 | * Check if the person dictionary has skills key, if so check if the person has 'Python' skill and print out the result. 86 | * If a person skills has only JavaScript and React, print('He is a front end developer'), if the person skills has Node, Python, MongoDB, print('He is a backend developer'), if the person skills has React, Node and MongoDB, Print('He is a fullstack developer'), else print('unknown title') - for more accurate results more conditions can be nested! 87 | * If the person is married and if he lives in Finland, print the information in the following format: 88 | 89 | ```py 90 | Asabeneh Yetayeh lives in Finland. He is married. 91 | ``` 92 | 93 | [<< Day 8](../Day%2008/README.md) | [Day 10 >>](../Day%2010/README.md) 94 | 95 | 96 | --#### [Go to Top of Page](#objective) 97 | -------------------------------------------------------------------------------- /Day 22/Python Syntax/Day22 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day TwentyTwo of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 01 Mar 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | # import the "re" module 16 | import re 17 | import collections 18 | import datetime 19 | from itertools import chain 20 | import json 21 | import csv 22 | import numpy as np 23 | import webbrowser 24 | import matplotlib as plt 25 | import requests 26 | import statistics 27 | import pandas as pd 28 | from bs4 import BeautifulSoup 29 | 30 | 31 | def main(): 32 | os.system("cls") # clear console 33 | 34 | def p(num): 35 | print(f"Number {num}") 36 | 37 | def pn(num = 1): 38 | print(f"\n" * num) 39 | 40 | def bannergreeting(day_name,exercise_name): 41 | daybanner = f'Exercise {day_name} ' 42 | exercisebanner = f'Level {exercise_name} ' 43 | front_end = f'--' * 20 44 | return combinebanners(front_end,daybanner,exercisebanner) 45 | 46 | def combinebanners(s0,s1,s2): 47 | return s0 + s1 + s2 + s0 48 | 49 | banner = bannergreeting 50 | print(banner(22,1)) 51 | 52 | #1. Scrape the following website and store the data as json file(url = 'http://www.bu.edu/president/boston-university-facts-stats/'). 53 | p(1) 54 | boston_uni_url = 'http://www.bu.edu/president/boston-university-facts-stats/' 55 | bu_response = requests.get(boston_uni_url) 56 | bu_response_content = bu_response.content # we get all the content from the website 57 | soup = BeautifulSoup(bu_response_content,features='lxml')# beautiful soup will give a chance to parse 58 | print(soup.title) # BU Facts & Stats | Office of the President 59 | print(soup.title.get_text()) # BU Facts & Stats | Office of the President 60 | print(bu_response.status_code) 61 | 62 | 63 | #Get Data tables in Website 64 | bu_stats = soup.find_all(class_="facts-wrapper") 65 | table_stat_dictlist,txt_items_combined,txt_values_combined = [],[],[] 66 | for i in bu_stats: 67 | txt_t_items = [j.get_text() for j in i.find_all(class_="text")] 68 | txt_t_values = [j.get_text() for j in i.find_all(class_="value")] 69 | txt_items_combined.append(txt_t_items) 70 | txt_values_combined.append(txt_t_values) 71 | table_stat_dictlist.append(dict(zip(txt_t_items,txt_t_values))) 72 | with open("bu_stats.json",'w') as bu_json: 73 | json.dump(table_stat_dictlist,bu_json) #write to file 74 | 75 | #2 Extract the table in this url (https://archive.ics.uci.edu/ml/datasets.php) and change it to a json file 76 | ml_url = 'https://archive.ics.uci.edu/ml/datasets.php' 77 | 78 | response = requests.get(ml_url) 79 | content = response.content # we get all the content from the website 80 | soup = BeautifulSoup(content, 'html.parser') # beautiful soup will give a chance to parse 81 | print(response.status_code) 82 | tables = soup.find_all('table', {'cellpadding':'3'}) # 83 | table = tables[0] 84 | s = '' 85 | for td in table.find('tr').find_all('td'): 86 | s += td.text 87 | 88 | with open("ml_stats.json",'w') as ml_json: 89 | json.dump(s,ml_json) #write to file 90 | 91 | #3 Scrape the presidents table and store the data as json 92 | uspres_url = 'https://en.wikipedia.org/wiki/List_of_presidents_of_the_United_States' 93 | response = requests.get(uspres_url) 94 | content = response.content 95 | soup = BeautifulSoup(content, 'html.parser') 96 | print(soup.title) 97 | print(soup.title.get_text()) 98 | print(response.status_code) 99 | 100 | tables = soup.find_all('table', class_ = "wikitable sortable") 101 | pres_table = tables[0] # the result is a list, we are taking out data from it 102 | 103 | for td in pres_table.find_all('td'): 104 | s += td.text 105 | 106 | with open("us_presidents.json",'w') as us_pres_json: 107 | json.dump(s,us_pres_json) 108 | 109 | if __name__ == "__main__": 110 | main() 111 | -------------------------------------------------------------------------------- /Day 02/Python Syntax/Day02 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Two of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 02 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | 16 | 17 | 18 | def main(): 19 | def comparelength(int1,int2): 20 | if int1 > int2: 21 | print("First Name is longer than Last Name") 22 | elif int1 < int2: 23 | print("First Name is shorter than Last Name") 24 | else: 25 | print("First Name and Last Names have same length") 26 | 27 | os.system("cls") # clear console 28 | s0, s1 = "", 'Exercise level 1' 29 | s2 = 'Exercise level 2' 30 | 31 | for i in range(20): 32 | s0 += "@:" 33 | 34 | s = s0 + s1 + s0 35 | print(s) 36 | 37 | tempstr = os.path.curdir 38 | foldername = "Variable Folder" 39 | try: 40 | os.makedirs(foldername) 41 | except FileExistsError: 42 | print("Directory " , foldername , " already exists") 43 | newpath = os.path.join(tempstr, foldername) 44 | os.chdir(newpath) 45 | try: 46 | myfile = open("variables.py","w+") 47 | myfile.close() 48 | print("File \'" + myfile.name + "\' created or updated") 49 | except: 50 | print("Error updating or writing to file") 51 | 52 | #Write a python comment saying 'Day 2: 30 Days of python programming' 53 | 54 | fname, lastname = "John","Constantine" 55 | fullname = fname + ' ' + lastname 56 | mycountry = "gitland" 57 | mycity = "gitville" 58 | myage = 18 59 | myyear = 2022 60 | is_married = False 61 | is_true = True 62 | is_lighton= True 63 | 64 | myString2 = "Variable: {} is of data type:-\t{}" 65 | s = s0 + s2 + s0 66 | print(s) 67 | #1. Check data types of the variables 68 | 69 | print (myString2.format(fname,type(fname))) 70 | print (myString2.format(lastname,type(lastname))) 71 | print (myString2.format(fullname,type(fullname))) 72 | print (myString2.format(mycountry,type(mycountry))) 73 | print (myString2.format(mycity,type(mycity))) 74 | print (myString2.format(myage,type(myage))) 75 | print (myString2.format(myyear,type(myyear))) 76 | print (myString2.format(is_married,type(is_married))) 77 | print (myString2.format(is_true,type(is_true))) 78 | print (myString2.format(is_lighton,type(is_lighton))) 79 | 80 | #2 81 | print ("Length of firstname: \""+ fname+"\" is "+ str(len(fname))) 82 | 83 | #3 84 | print ("Length of fullname: \""+ fullname+"\" is "+ str(len(fullname))) 85 | lenfirst, lenlast = len(fname), len(lastname) 86 | comparelength(lenfirst,lenlast) 87 | 88 | #4 89 | num_one, num_two = 5,4 90 | total = num_one+ num_two 91 | var_diff = num_one-num_two 92 | var_product = num_one*num_two 93 | var_remainder = num_one%num_two 94 | var_exp = num_one**num_two 95 | var_floor_div = num_one//num_two 96 | 97 | print(total) 98 | print(var_diff) 99 | print(var_product) 100 | print(var_remainder) 101 | print(var_exp) 102 | print(var_floor_div) 103 | 104 | #5 105 | circleRadius = 30 106 | area_of_circle = math.pi * 30 ** 2 107 | circum_of_circle = math.pi * 30 * 2 108 | 109 | try: 110 | userradius = int(input("Enter a user-defined circle radius:\n")) 111 | except: 112 | print("Enter a valid number!\n") 113 | userradius = int(input("Enter a user-defined circle radius:\n")) 114 | print("Area of Circle with radius "+str(userradius) + " meters is " + "{:.2f}".format(math.pi * userradius ** 2)) 115 | 116 | #6 117 | string1 = input("Please input your first name:\n") 118 | string2 = input("Please input your last name:\n") 119 | string3 = input("Please input your country\n") 120 | string4 = input("Please input your age\n") 121 | 122 | #7 123 | help('keywords') 124 | 125 | 126 | if __name__ == "__main__": 127 | main() 128 | -------------------------------------------------------------------------------- /Day 20/Day20 Solution.txt: -------------------------------------------------------------------------------- 1 | ----------------------------------------Exercise 20 Level 1 ---------------------------------------- 2 | Number 1 3 | [(762, 'the'), (560, 'I'), (539, 'and'), (522, 'to'), (487, 'of'), (453, 'a'), (332, 'in'), (325, 'is'), (310, 'my'), (277, 'you')] 4 | 5 | 6 | Number 2 7 | 200 8 | 2(i) the following are the statistics for weight: 9 | [3, 3, 3, 3, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 6, 6, 6, 6, 6.5, 6.5, 6.5, 7, 7, 7.5] in kg 10 | min: 3 kg max 7.5 kg 11 | mean: 4.7 kg median 4.5 kg 12 | standard deviation: 1.067 kg 13 | 14 | 15 | 2(ii) the following are the statistics for lifespan: 16 | [10.5, 11, 11, 11, 12, 12, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 14, 14, 14, 14, 14, 14, 14, 14, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 15, 15, 15, 15, 15.5, 16, 16, 16.5, 16.5, 17.5, 18.5, 19] in years 17 | min: 10.5 years max 19 years 18 | mean: 13.7 years median 13.5 years 19 | standard deviation: 1.584 years 20 | 21 | 22 | 2(iii) the following are the frequency distribution: 23 | Country Frequency 24 | 0 United States 28 25 | 1 United Kingdom 8 26 | 2 Russia 4 27 | 3 Thailand 4 28 | 4 Egypt 3 29 | 5 Canada 3 30 | 6 France 2 31 | 7 Burma 2 32 | 8 Turkey 2 33 | 9 Greece 1 34 | 10 United Arab Emirates 1 35 | 11 Australia 1 36 | 12 Cyprus 1 37 | 13 China 1 38 | 14 Japan 1 39 | 15 Isle of Man 1 40 | 16 Norway 1 41 | 17 Iran (Persia) 1 42 | 18 Singapore 1 43 | 19 Somalia 1 44 | 45 | Number 4 46 | 629 47 | 0 1 2 3 4 5 6 48 | 0 Name Data Types Default Task Attribute Types # Instances # Attributes Year 49 | 1 Abalone Multivariate Classification Categorical, Integer, Real 4177 8 1995 50 | 2 Adult Multivariate Classification Categorical, Integer 48842 14 1996 51 | 3 Annealing Multivariate Classification Categorical, Integer, Real 798 38 NaN 52 | 4 Anonymous Microsoft Web Data NaN Recommender-Systems Categorical 37711 294 1998 53 | .. ... ... ... ... ... ... ... 54 | 618 Influenza outbreak event prediction via Twitte... Multivariate Classification Integer, Real 75840 525 2020 55 | 619 Turkish Music Emotion Dataset Multivariate Classification Integer, Real 400 50 2020 56 | 620 Maternal Health Risk Data Set NaN Classification NaN 1014 7 2020 57 | 621 Room Occupancy Estimation Multivariate, Time-Series Classification Real 10129 16 2021 58 | 622 Image Recognition Task Execution Times in Mobi... Univariate Regression Real 4000 2 2021 -------------------------------------------------------------------------------- /Day 04/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Four 4 | 5 | ## 📚 Table of Contents 6 | - [💻 Exercises - Day 4](#-exercises---day-4) 7 | - [Syntax on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2004/Python%20Syntax/Day04%20Syntax.py) 8 | 9 | 10 | ## Objective 11 | This repository contains the solution for the Day Four of the "30 Days of Python Challenge"! 12 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 13 | 14 | 15 | ## 💻 Exercises - Day 4 16 | 17 | 1. Concatenate the string 'Thirty', 'Days', 'Of', 'Python' to a single string, 'Thirty Days Of Python'. 18 | 2. Concatenate the string 'Coding', 'For' , 'All' to a single string, 'Coding For All'. 19 | 3. Declare a variable named company and assign it to an initial value "Coding For All". 20 | 4. Print the variable company using _print()_. 21 | 5. Print the length of the company string using _len()_ method and _print()_. 22 | 6. Change all the characters to uppercase letters using _upper()_ method. 23 | 7. Change all the characters to lowercase letters using _lower()_ method. 24 | 8. Use capitalize(), title(), swapcase() methods to format the value of the string _Coding For All_. 25 | 9. Cut(slice) out the first word of _Coding For All_ string. 26 | 10. Check if _Coding For All_ string contains a word Coding using the method index, find or other methods. 27 | 11. Replace the word coding in the string 'Coding For All' to Python. 28 | 12. Change Python for Everyone to Python for All using the replace method or other methods. 29 | 13. Split the string 'Coding For All' using space as the separator (split()) . 30 | 14. "Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon" split the string at the comma. 31 | 15. What is the character at index 0 in the string _Coding For All_. 32 | 16. What is the last index of the string _Coding For All_. 33 | 17. What character is at index 10 in "Coding For All" string. 34 | 18. Create an acronym or an abbreviation for the name 'Python For Everyone'. 35 | 19. Create an acronym or an abbreviation for the name 'Coding For All'. 36 | 20. Use index to determine the position of the first occurrence of C in Coding For All. 37 | 21. Use index to determine the position of the first occurrence of F in Coding For All. 38 | 22. Use rfind to determine the position of the last occurrence of l in Coding For All People. 39 | 23. Use index or find to 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' 40 | 24. Use rindex to find the position of the last occurrence of the word because in the following sentence: 'You cannot end a sentence with because because because is a conjunction' 41 | 25. Slice out the phrase 'because because because' in the following sentence: 'You cannot end a sentence with because because because is a conjunction' 42 | 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' 43 | 27. Slice out the phrase 'because because because' in the following sentence: 'You cannot end a sentence with because because because is a conjunction' 44 | 28. Does '\'Coding For All' start with a substring _Coding_? 45 | 29. Does 'Coding For All' end with a substring _coding_? 46 | 30. '   Coding For All      '  , remove the left and right trailing spaces in the given string. 47 | 31. Which one of the following variables return True when we use the method isidentifier(): 48 | - 30DaysOfPython 49 | - thirty_days_of_python 50 | 32. The following list contains the names of some of python libraries: ['Django', 'Flask', 'Bottle', 'Pyramid', 'Falcon']. Join the list with a hash with space string. 51 | 33. Use the new line escape sequence to separate the following sentences. 52 | ```py 53 | I am enjoying this challenge. 54 | I just wonder what is next. 55 | ``` 56 | 34. Use a tab escape sequence to write the following lines. 57 | ```py 58 | Name Age Country City 59 | Asabeneh 250 Finland Helsinki 60 | ``` 61 | 35. Use the string formatting method to display the following: 62 | 63 | ```sh 64 | radius = 10 65 | area = 3.14 * radius ** 2 66 | The area of a circle with radius 10 is 314 meters square. 67 | ``` 68 | 69 | 36. Make the following using string formatting methods: 70 | 71 | ```sh 72 | 8 + 6 = 14 73 | 8 - 6 = 2 74 | 8 * 6 = 48 75 | 8 / 6 = 1.33 76 | 8 % 6 = 2 77 | 8 // 6 = 1 78 | 8 ** 6 = 262144 79 | ``` 80 | -------------------------------------------------------------------------------- /Day 11/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day Eleven 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 1](#-exercises-day-11) 8 | - [Exercise: Level 1](#exercises-level-1) 9 | - [Exercise: Level 2](#exercises-level-2) 10 | - [Exercise: Level 3](#exercises-level-3) 11 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2011/Python%20Syntax/Day11%20Syntax.py) 12 | 13 | 14 | ## Objective 15 | This repository contains the solution for the Day Eleven of the "30 Days of Python Challenge"! 16 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 17 | 18 | ## 💻 Exercises: Day 11 19 | 20 | ### Exercises: Level 1 21 | 22 | 1. Declare a function _add_two_numbers_. It takes two parameters and it returns a sum. 23 | 2. Area of a circle is calculated as follows: area = π x r x r. Write a function that calculates _area_of_circle_. 24 | 3. Write a function called add_all_nums which takes arbitrary number of arguments and sums all the arguments. Check if all the list items are number types. If not do give a reasonable feedback. 25 | 4. Temperature in °C can be converted to °F using this formula: °F = (°C x 9/5) + 32. Write a function which converts °C to °F, _convert_celsius_to-fahrenheit_. 26 | 5. Write a function called check-season, it takes a month parameter and returns the season: Autumn, Winter, Spring or Summer. 27 | 6. Write a function called calculate_slope which return the slope of a linear equation 28 | 7. Quadratic equation is calculated as follows: ax² + bx + c = 0. Write a function which calculates solution set of a quadratic equation, _solve_quadratic_eqn_. 29 | 8. Declare a function named print_list. It takes a list as a parameter and it prints out each element of the list. 30 | 9. Declare a function named reverse_list. It takes an array as a parameter and it returns the reverse of the array (use loops). 31 | 32 | ```py 33 | print(reverse_list([1, 2, 3, 4, 5])) 34 | # [5, 4, 3, 2, 1] 35 | print(reverse_list1(["A", "B", "C"])) 36 | # ["C", "B", "A"] 37 | ``` 38 | 39 | 10. Declare a function named capitalize_list_items. It takes a list as a parameter and it returns a capitalized list of items 40 | 11. Declare a function named add_item. It takes a list and an item parameters. It returns a list with the item added at the end. 41 | 42 | ```py 43 | food_staff = ['Potato', 'Tomato', 'Mango', 'Milk']; 44 | print(add_item(food_staff, 'Meat')) # ['Potato', 'Tomato', 'Mango', 'Milk','Meat']; 45 | numbers = [2, 3, 7, 9]; 46 | print(add_item(numbers, 5)) [2, 3, 7, 9, 5] 47 | ``` 48 | 49 | 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. 50 | 51 | ```py 52 | food_staff = ['Potato', 'Tomato', 'Mango', 'Milk']; 53 | print(remove_item(food_staff, 'Mango')) # ['Potato', 'Tomato', 'Milk']; 54 | numbers = [2, 3, 7, 9]; 55 | print(remove_item(numbers, 3)) # [2, 7, 9] 56 | ``` 57 | 58 | 13. Declare a function named sum_of_numbers. It takes a number parameter and it adds all the numbers in that range. 59 | 60 | ```py 61 | print(sum_of_numbers(5)) # 15 62 | print(sum_all_numbers(10)) # 55 63 | print(sum_all_numbers(100)) # 5050 64 | ``` 65 | 66 | 14. Declare a function named sum_of_odds. It takes a number parameter and it adds all the odd numbers in that range. 67 | 15. Declare a function named sum_of_even. It takes a number parameter and it adds all the even numbers in that - range. 68 | 69 | ### Exercises: Level 2 70 | 71 | 1. Declare a function named evens_and_odds . It takes a positive integer as parameter and it counts number of evens and odds in the number. 72 | 73 | ```py 74 | print(evens_and_odds(100)) 75 | # The number of odds are 50. 76 | # The number of evens are 51. 77 | ``` 78 | 79 | 1. Call your function factorial, it takes a whole number as a parameter and it return a factorial of the number 80 | 1. Call your function _is_empty_, it takes a parameter and it checks if it is empty or not 81 | 1. Write different functions which take lists. They should calculate_mean, calculate_median, calculate_mode, calculate_range, calculate_variance, calculate_std (standard deviation). 82 | 83 | ### Exercises: Level 3 84 | 85 | 1. Write a function called is_prime, which checks if a number is prime. 86 | 1. Write a functions which checks if all items are unique in the list. 87 | 1. Write a function which checks if all the items of the list are of the same data type. 88 | 1. Write a function which check if provided variable is a valid python variable 89 | 1. Go to the data folder and access the countries-data.py file. 90 | 91 | - Create a function called the most_spoken_languages in the world. It should return 10 or 20 most spoken languages in the world in descending order 92 | - Create a function called the most_populated_countries. It should return 10 or 20 most populated countries in descending order. 93 | 94 | 95 | [<< Day 10](../Day%2010/README.md) | [Day 12 >>](../Day%2012/README.md) 96 | 97 | 98 | --#### [Go to Top of Page](#objective) 99 | -------------------------------------------------------------------------------- /Day 19/Day19 Solution.txt: -------------------------------------------------------------------------------- 1 | ----------------------------------------Exercise 19 Level 1 ---------------------------------------- 2 | Number 1 3 | obama_speech.txt has 66 lines 4 | michelle_obama_speech.txt has 83 lines 5 | donald_speech.txt has 48 lines 6 | melina_trump_speech.txt has 33 lines 7 | 8 | Number 2 9 | print(topten_languages(c_data,3)) 10 | The 3 most common lanaguages are; 11 | 12 | ('English', 91) 13 | ('French', 45) 14 | ('Arabic', 25) 15 | 16 | print(topten_languages(c_data,10)) 17 | The 10 most common lanaguages are; 18 | ('English', 91) 19 | ('French', 45) 20 | ('Arabic', 25) 21 | ('Spanish', 24) 22 | ('Portuguese', 9) 23 | ('Russian', 9) 24 | ('Dutch', 8) 25 | ('German', 7) 26 | ('Chinese', 5) 27 | ('Serbian', 4) 28 | 29 | Number 3 30 | print(topten_pop(c_data,3)) 31 | print(topten_pop(c_data,10)) 32 | 33 | The 3 most populated countries are; 34 | {'name': 'China', 'languages': ['Chinese'], 'population': 1377422166} 35 | {'name': 'India', 'languages': ['Hindi', 'English'], 'population': 1295210000} 36 | {'name': 'United States of America', 'languages': ['English'], 'population': 323947000} 37 | 38 | The 10 most populated countries are; 39 | {'name': 'China', 'languages': ['Chinese'], 'population': 1377422166} 40 | {'name': 'India', 'languages': ['Hindi', 'English'], 'population': 1295210000} 41 | {'name': 'United States of America', 'languages': ['English'], 'population': 323947000} 42 | {'name': 'Indonesia', 'languages': ['Indonesian'], 'population': 258705000} 43 | {'name': 'Brazil', 'languages': ['Portuguese'], 'population': 206135893} 44 | {'name': 'Pakistan', 'languages': ['English', 'Urdu'], 'population': 194125062} 45 | {'name': 'Nigeria', 'languages': ['English'], 'population': 186988000} 46 | {'name': 'Bangladesh', 'languages': ['Bengali'], 'population': 161006790} 47 | {'name': 'Russian Federation', 'languages': ['Russian'], 'population': 146599183} 48 | {'name': 'Japan', 'languages': ['Japanese'], 'population': 126960000} 49 | 50 | Number 4: Output in file 'from_emails.txt' 51 | 52 | Number 5 53 | [(120, 'the'), (107, 'and'), (81, 'of'), (66, 'to'), (58, 'our'), (50, 'we'), (49, 'that'), (48, 'a'), (36, 'is'), (23, '-')] 54 | 55 | Number 6 56 | [(61, 'the'), (53, 'and'), (40, 'will'), (38, 'of'), (32, 'to'), (30, 'our'), (26, 'we'), (20, 'is'), (16, 'We'), (16, 'America')] 57 | [(73, 'and'), (54, 'to'), (48, 'the'), (28, 'I'), (28, 'is'), (27, 'for'), (25, 'of'), (22, 'a'), (19, 'that'), (17, 'Donald')] 58 | [(84, 'to'), (80, 'and'), (78, 'the'), (46, 'of'), (41, '—'), (41, 'a'), (40, 'that'), (36, 'in'), (27, 'for'), (27, 'our')] 59 | 60 | Number 7 61 | The rate of similarity is: 46.1968702209566 % 62 | The similar words are: {'brother', 'compassion', 'love', 'like', 'me', 'serve', 'speak', 'worked', 'moved', 'young', 'each', 'ago,', 'you', 'work', 'they', 'people', 'moment', 'bless', 'on', 'today', 'gets', 'by', 'this', 'my', 'Because', 'together', 'go', 'years', 'them', 'one', 'simple', 'give', 'whole', 'new', 'come', 'You', '18', 'across', 'be', 'long', 'today,', 'those', 'nation', 'who', 'their', 'working', 'is', 'future', 'room', 'among', 'even', 'God', 'these', 'as', 'and', 'have', 63 | 'country', 'We', 'Their', 'say', 'so', 'bond', 'way', 'a', 'was', 'it', 'make', 'memory', 'also', 'through', 'House', 'integrity,', 'comes', 'of', 'can', 'up', 'family', 'or', 'hard-working', 'husband,', 'bring', 'without', 'mother', 'are', 'next', 'America', 'president', 'education', 'help', 'than', 'ready', '—', 'word', 'hard', 'I', 'get', 'much', 'his', 'ensure', 'life;', 'caring', 'with', 'done', 'do', 'want', 'let', 'father', 'He', 'he', 'know', 'strength', 'since', 'loves', 'man', 'opportunity', 'values', 'other', 'generation', 'parents', 'into', 'our', 'son', 'us', 'world', 'change', 'what', 'gratitude', 'here', 'honor', 'from', 'been', 'many', 'opportunities', 'raised', 'safe', 'down', 'him', 'where', 'millions', 'first', 'good', 'day,', 'determination', 'had', 'The', 'all', 'treat', "won't", 'someone', 'for', 'fell', 'sacrifices', 'They', 'keep', 'willingness', 'should', 'we', 'As', 'at', 'there', 'to', 'day', 'always', 'every', 'greatest', 'limit', 'when', 'introduced', 'heart', 'that', 'along', 'about', 'just', 'the', 'My', 'while', 'Like', 'And', 'small', "It's", 'child', '"', 'most', 'best', 'But', 'never', 'children', 'programs', 'only', 'fairness', 'sister', 'That', 'try', 'your', 'ever', 'tell', 'White', 'need', 'States', 'family,', 'no', 'you,', 'not', 'in', 'life', 'brought', 'will', 'but', 'living', 'both', 'great', 'achievements', 'husband', 64 | 'pass', 'an', 'intelligence', 'knows', 'dreams', 'were', 'parents,', 'women', 'met', 'is,', 'has', 65 | 'Thank', 'before', 'United', 'how', 'blessed', 'People', 'joys', 'Americans', 'fight'} 66 | 67 | Number 8 68 | [(762, 'the'), (560, 'I'), (539, 'and'), (522, 'to'), (487, 'of'), (453, 'a'), (332, 'in'), (325, 'is'), (310, 'my'), (277, 'you')] 69 | 70 | Number 9 71 | Hackerfile has 20100 rows with "Python or python" found in 179 lines. 72 | Hackerfile has 20100 rows with "JavaScript or javaScript or javascript" found in 184 lines. 73 | Hackerfile has 20100 rows with "Java" found in 52 lines. 74 | -------------------------------------------------------------------------------- /Day 20/Python Syntax/Day20 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Twenty of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 25 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | # import the "re" module 16 | import re 17 | import collections 18 | import datetime 19 | from itertools import chain 20 | import json 21 | import csv 22 | import numpy 23 | import webbrowser 24 | import matplotlib 25 | import requests 26 | import statistics 27 | import pandas as pd 28 | 29 | def main(): 30 | os.system("cls") # clear console 31 | 32 | def p(num): 33 | print(f"Number {num}") 34 | 35 | def pn(num = 1): 36 | print(f"\n" * num) 37 | 38 | def bannergreeting(day_name,exercise_name): 39 | daybanner = f'Exercise {day_name} ' 40 | exercisebanner = f'Level {exercise_name} ' 41 | front_end = f'--' * 20 42 | return combinebanners(front_end,daybanner,exercisebanner) 43 | 44 | def combinebanners(s0,s1,s2): 45 | return s0 + s1 + s2 + s0 46 | 47 | 48 | banner = bannergreeting 49 | print(banner(20,1)) 50 | 51 | def top_words_in_english(all_text, num_extract = 10): 52 | list_words,templist = [],[] 53 | seperate_words = list(filter(None,re.split('\s+|\.',all_text))) 54 | words_group = collections.Counter(seperate_words) 55 | w_tp = words_group.items() 56 | w_tp2 = [(b,a) for (a,b) in w_tp] 57 | w_tuple = sorted(w_tp2,key = lambda k:k[0],reverse=True) 58 | return w_tuple[0:num_extract] 59 | 60 | def cleanuprange(cellrange): 61 | cell1 = [] 62 | m = re.findall('\d+', cellrange) 63 | for i in m: 64 | cell1.append(int(i)) 65 | return tuple(cell1) 66 | 67 | #1.Read this url and find the 10 most frequent words. romeo_and_juliet = 'http://www.gutenberg.org/files/1112/1112.txt' 68 | p(1) 69 | romeo_and_juliet = 'http://www.gutenberg.org/files/1112/1112.txt' 70 | r_j_response = requests.get(romeo_and_juliet) 71 | print(r_j_response.status_code) 72 | print(r_j_response.headers) 73 | text_to_search = r_j_response.text 74 | print(top_words_in_english(text_to_search)) 75 | 76 | #2. Read the cats API and cats_api = 'https://api.thecatapi.com/v1/breeds' and find : 77 | # the min, max, mean, median, standard deviation of cats' weight in metric units. 78 | # the min, max, mean, median, standard deviation of cats' lifespan in years. 79 | # Create a frequency table of country and breed of cats 80 | 81 | p(2) 82 | cat_api = 'https://api.thecatapi.com/v1/breeds' 83 | response = requests.get(cat_api) 84 | c1 = response.json() 85 | print(len(c1)) #67 breeds 86 | 87 | #"weight" := { "imperial" := "8 - 15" , "metric" := "4 - 7"} 88 | #use the values: ('7 - 10', '3 - 5') pick the metric 89 | a,cat_weight,cat_life,cat_country_breed = [],[],[],[] 90 | for cat_data in c1: 91 | w = tuple(cat_data["weight"].values())[1] 92 | l = cat_data["life_span"] 93 | c = cat_data["origin"] 94 | a.append(list((w,l,c))) #['5 - 8', '13 - 15', 'United States'] weight in kg, years and country 95 | 96 | catdata_stat = [] 97 | for i in a: 98 | templist = [] 99 | templist.append(cleanuprange(i[0])) #[(5,8),(13,15), 'United States'] weight in kg, years and country 100 | templist.append(cleanuprange(i[1])) 101 | templist.append(i[2]) 102 | catdata_stat.append(templist) 103 | 104 | c_data_for_statistics = [] 105 | for i in catdata_stat: 106 | templist = [] 107 | templist.append(statistics.mean(i[0])) 108 | templist.append(statistics.mean(i[1])) 109 | templist.append(i[2]) 110 | c_data_for_statistics.append(templist) #[6.5, 14, 'United States']] 111 | 112 | c_weight,c_years,c_freq = [],[],[] 113 | for i in c_data_for_statistics: 114 | c_weight.append(i[0]) 115 | c_years.append(i[1]) 116 | c_freq.append(i[2]) 117 | 118 | c_freq_tuple = sorted(collections.Counter(c_freq).items(),key = lambda x:x[1],reverse = True) 119 | print(c_freq_tuple) 120 | 121 | #Unzip the tuple 122 | cat_country, cat_frequency = zip(*c_freq_tuple) 123 | 124 | country_series = pd.Series(cat_country) 125 | freq_series = pd.Series(cat_frequency) 126 | 127 | frame = { 'Country': country_series, 'Frequency': freq_series } 128 | result = pd.DataFrame(frame) 129 | 130 | 131 | print(f"""2(i) the following are the statistics for weight: 132 | {sorted(c_weight)} in kg 133 | min: {min(c_weight)} kg \t max {max(c_weight)} kg 134 | mean: {statistics.mean(c_weight):.1f} kg \t median {statistics.median(c_weight)} kg 135 | standard deviation: {statistics.stdev(c_weight):.3f} kg """) 136 | pn() 137 | 138 | print(f"""2(ii) the following are the statistics for lifespan: 139 | {sorted(c_years)} in years 140 | min: {min(c_years)} years \t max {max(c_years)} years 141 | mean: {statistics.mean(c_years):.1f} years \t median {statistics.median(c_years)} years 142 | standard deviation: {statistics.stdev(c_years):.3f} years """) 143 | pn() 144 | 145 | print(f"""2(iii) the following are the frequency distribution: 146 | {result} """) 147 | pn() 148 | p(3) 149 | 150 | p(4) 151 | url_ml = 'https://archive.ics.uci.edu/ml/datasets.php' 152 | df = pd.read_html(url_ml) 153 | print(len(df)) #629 items in the list table starts from 5 154 | dataset_table = df[5] 155 | print(df[5]) 156 | 157 | 158 | 159 | if __name__ == "__main__": 160 | main() 161 | -------------------------------------------------------------------------------- /Day 22/us_presidents.json: -------------------------------------------------------------------------------- 1 | "\nGeorge Washington(1732\u20131799)\nApril 30, 1789\u2013March 4, 1797\n\nUnaffiliated\n1788\u201389\nJohn Adams[c]\n1792\n\nJohn Adams(1735\u20131826)\nMarch 4, 1797\u2013March 4, 1801\n\nFederalist\n1796\nThomas Jefferson[d]\n\nThomas Jefferson(1743\u20131826)\nMarch 4, 1801\u2013March 4, 1809\n\nDemocratic-Republican\n1800\nAaron Burr\n1804\nGeorge Clinton[e]\n\nJames Madison(1751\u20131836)\nMarch 4, 1809\u2013March 4, 1817\n\nDemocratic-Republican\n1808\nVacant\u00a0afterApr. 20, 1812\n1812\nElbridge Gerry[e]\nVacant\u00a0afterNov. 23, 1814\n\nJames Monroe(1758\u20131831)\nMarch 4, 1817\u2013March 4, 1825\n\nDemocratic-Republican\n1816\nDaniel D. Tompkins\n1820\n\nJohn Quincy Adams(1767\u20131848)\nMarch 4, 1825\u2013March 4, 1829\n\nDemocratic-Republican[f]\n1824\nJohn C. Calhoun[g][h]\n\nNational Republican\n\nAndrew Jackson(1767\u20131845)\nMarch 4, 1829\u2013March 4, 1837\n\nDemocratic\n1828\nVacant\u00a0afterDec. 28, 1832\n1832\nMartin Van Buren\n\nMartin Van Buren(1782\u20131862)\nMarch 4, 1837\u2013March 4, 1841\n\nDemocratic\n1836\nRichard Mentor Johnson\n\nWilliam Henry Harrison[e](1773\u20131841)\nMarch 4, 1841\u2013April 4, 1841\n\nWhig\n1840\nJohn Tyler\n\nJohn Tyler(1790\u20131862)\nApril 4, 1841[i]\u2013March 4, 1845\n\nWhig[j]\nVacant\u00a0throughoutpresidency\n\nUnaffiliated\n\nJames K. Polk(1795\u20131849)\nMarch 4, 1845\u2013March 4, 1849\n\nDemocratic\n1844\nGeorge M. Dallas\n\nZachary Taylor[e](1784\u20131850)\nMarch 4, 1849\u2013July 9, 1850\n\nWhig\n1848\nMillard Fillmore\n\nMillard Fillmore(1800\u20131874)\nJuly 9, 1850[k]\u2013March 4, 1853\n\nWhig\nVacant\u00a0throughoutpresidency\n\nFranklin Pierce(1804\u20131869)\nMarch 4, 1853\u2013March 4, 1857\n\nDemocratic\n1852\nWilliam R. King[e]\nVacant\u00a0afterApr. 18, 1853\n\nJames Buchanan(1791\u20131868)\nMarch 4, 1857\u2013March 4, 1861\n\nDemocratic\n1856\nJohn C. Breckinridge\n\nAbraham Lincoln[l](1809\u20131865)\nMarch 4, 1861\u2013April 15, 1865\n\nRepublican\n1860\nHannibal Hamlin\n\nNational Union[m]\n1864\nAndrew Johnson\n\nAndrew Johnson(1808\u20131875)\nApril 15, 1865\u2013March 4, 1869\n\nNational Union[n]\nVacant\u00a0throughoutpresidency\n\nDemocratic\n\nUlysses S. Grant(1822\u20131885)\nMarch 4, 1869\u2013March 4, 1877\n\nRepublican\n1868\nSchuyler Colfax\n1872\nHenry Wilson[e]\nVacant\u00a0afterNov. 22, 1875\n\nRutherford B. Hayes(1822\u20131893)\nMarch 4, 1877\u2013March 4, 1881\n\nRepublican\n1876\nWilliam A. Wheeler\n\nJames A. Garfield[o](1831\u20131881)\nMarch 4, 1881\u2013September 19, 1881\n\nRepublican\n1880\nChester A. Arthur\n\nChester A. Arthur(1829\u20131886)\nSeptember 19, 1881[p]\u2013March 4, 1885\n\nRepublican\nVacant\u00a0throughoutpresidency\n\nGrover Cleveland(1837\u20131908)\nMarch 4, 1885\u2013March 4, 1889\n\nDemocratic\n1884\nThomas A. Hendricks[e]\nVacant\u00a0afterNov. 25, 1885\n\nBenjamin Harrison(1833\u20131901)\nMarch 4, 1889\u2013March 4, 1893\n\nRepublican\n1888\nLevi P. Morton\n\nGrover Cleveland(1837\u20131908)\nMarch 4, 1893\u2013March 4, 1897\n\nDemocratic\n1892\nAdlai Stevenson\u00a0I\n\nWilliam McKinley[q](1843\u20131901)\nMarch 4, 1897\u2013September 14, 1901\n\nRepublican\n1896\nGarret Hobart[e]\nVacant\u00a0afterNov. 21, 1899\n1900\nTheodore Roosevelt\n\nTheodore Roosevelt(1858\u20131919)\nSeptember 14, 1901\u2013March 4, 1909\n\nRepublican\nVacant\u00a0throughMar. 4, 1905\n1904\nCharles W. Fairbanks\n\nWilliam Howard Taft(1857\u20131930)\nMarch 4, 1909\u2013March 4, 1913\n\nRepublican\n1908\nJames S. Sherman[e]\nVacant\u00a0afterOct. 30, 1912\n\nWoodrow Wilson(1856\u20131924)\nMarch 4, 1913\u2013March 4, 1921\n\nDemocratic\n1912\nThomas R. Marshall\n1916\n\nWarren G. Harding[e](1865\u20131923)\nMarch 4, 1921\u2013August 2, 1923\n\nRepublican\n1920\nCalvin Coolidge\n\nCalvin Coolidge(1872\u20131933)\nAugust 2, 1923[r]\u2013March 4, 1929\n\nRepublican\nVacant\u00a0throughMar. 4, 1925\n1924\nCharles G. Dawes\n\nHerbert Hoover(1874\u20131964)\nMarch 4, 1929\u2013March 4, 1933\n\nRepublican\n1928\nCharles Curtis\n\nFranklin D. Roosevelt[e](1882\u20131945)\nMarch 4, 1933\u2013April 12, 1945\n\nDemocratic\n1932\nJohn Nance Garner\n1936\n1940\nHenry A. Wallace\n1944\nHarry S. Truman\n\nHarry S. Truman(1884\u20131972)\nApril 12, 1945\u2013January 20, 1953\n\nDemocratic\nVacant\u00a0throughJan. 20, 1949\n1948\nAlben W. Barkley\n\nDwight D. Eisenhower(1890\u20131969)\nJanuary 20, 1953\u2013January 20, 1961\n\nRepublican\n1952\nRichard Nixon\n1956\n\nJohn F. Kennedy[s](1917\u20131963)\nJanuary 20, 1961\u2013November 22, 1963\n\nDemocratic\n1960\nLyndon B. Johnson\n\nLyndon B. Johnson(1908\u20131973)\nNovember 22, 1963\u2013January 20, 1969\n\nDemocratic\nVacant\u00a0throughJan. 20, 1965\n1964\nHubert Humphrey\n\nRichard Nixon[h](1913\u20131994)\nJanuary 20, 1969\u2013August 9, 1974\n\nRepublican\n1968\nSpiro Agnew[h]\n1972\nVacant, Oct. 10\u00a0\u2013 Dec. 6, 1973\nGerald Ford[t]\n\nGerald Ford(1913\u20132006)\nAugust 9, 1974\u2013January 20, 1977\n\nRepublican\nVacant\u00a0throughDec. 19, 1974\nNelson Rockefeller[t]\n\nJimmy Carter(b. 1924)\nJanuary 20, 1977\u2013January 20, 1981\n\nDemocratic\n1976\nWalter Mondale\n\nRonald Reagan(1911\u20132004)\nJanuary 20, 1981\u2013January 20, 1989\n\nRepublican\n1980\nGeorge H. W. Bush\n1984\n\nGeorge H. W. Bush(1924\u20132018)\nJanuary 20, 1989\u2013January 20, 1993\n\nRepublican\n1988\nDan Quayle\n\nBill Clinton(b. 1946)\nJanuary 20, 1993\u2013January 20, 2001\n\nDemocratic\n1992\nAl Gore\n1996\n\nGeorge W. Bush(b. 1946)\nJanuary 20, 2001\u2013January 20, 2009\n\nRepublican\n2000\nDick Cheney\n2004\n\nBarack Obama(b. 1961)\nJanuary 20, 2009\u2013January 20, 2017\n\nDemocratic\n2008\nJoe Biden\n2012\n\nDonald Trump(b. 1946)\nJanuary 20, 2017\u2013January 20, 2021\n\nRepublican\n2016\nMike Pence\n\nJoe Biden(b. 1942)\nJanuary 20, 2021\u2013Incumbent\n\nDemocratic\n2020\nKamala Harris\n" -------------------------------------------------------------------------------- /Day 06/Python Syntax/Day06 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Six of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 06 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | from math import ceil 15 | 16 | def main(): 17 | 18 | os.system("cls") # clear console 19 | 20 | s1 = 'Exercise level 1' 21 | s2 = 'Exercise level 2' 22 | s0 = '' 23 | 24 | for i in range(20): 25 | s0 += "@:" 26 | 27 | s = s0 + s1 + s0 28 | print(s) 29 | 30 | #1 Create an empty tuple 31 | mytuple = () 32 | print("Number 1") 33 | print("Empty Tuple: ", mytuple) 34 | 35 | tuple2 = tuple() 36 | print("Empty Tuple: ", tuple2) 37 | print("\n") 38 | 39 | #2 Create a tuple containing names of your sisters and your brothers (imaginary siblings are fine) 40 | print("Number 2") 41 | mytuple_bro = ("Luke Skywalker","Obi-Wan Kenobi","Mace Windu") 42 | mytuple_sis = ("Ahsoka Tahno","Leia Organa","Padme Amidala") 43 | print("Tuple - Brothers:", mytuple_bro) 44 | print("Tuple - Sisters:", mytuple_sis) 45 | print("\n") 46 | 47 | #3 Join brothers and sisters tuples and assign it to siblings 48 | print("Number 3") 49 | mytuple_siblings = mytuple_bro + mytuple_sis 50 | print("Tuple - Siblings:", mytuple_siblings) 51 | 52 | #method 2 53 | list_mytuple_siblings = list(mytuple_bro) 54 | list_mytuple_siblings.extend(mytuple_sis) 55 | print("Method 2- Using List to modify tuples workaround: ",tuple(list_mytuple_siblings)) 56 | print("\n") 57 | 58 | #4 How many siblings do you have? 59 | print("Number 4") 60 | print("Number of Siblings:", len(mytuple_siblings)) 61 | print("\n") 62 | 63 | #5 Modify the siblings tuple and add the name of your father and mother and assign it to family_members 64 | # Tuples cannot be modified 65 | print("Number 5") 66 | list_mytuple_family = list_mytuple_siblings.copy() #duplicate the old sibling list 67 | my_tuple_parents = tuple(("Master Yoda","Emperor Palpatine")) 68 | list_mytuple_family.append(my_tuple_parents) 69 | print("Family Tuple: ",tuple(list_mytuple_family)) 70 | print("\n") 71 | 72 | 73 | s = s0 + s2 + s0 74 | print(s) 75 | 76 | #1 Unpack siblings and parents from family_members 77 | print("Number 1") 78 | *siblings, parents = list_mytuple_family 79 | print("Sibling: ",siblings) 80 | print("Parents: ",parents) 81 | print("\n") 82 | 83 | #2 Create fruits, vegetables and animal products tuples. Join the three tuples and assign it to a variable called food_stuff_tp. 84 | print("Number 2") 85 | fruits = ('banana', 'orange', 'mango', 'lemon') 86 | vegetables = ('Tomato', 'Potato', 'Cabbage','Onion', 'Carrot') 87 | animal_products = ('fat', 'meat', 'milk','eggs') 88 | 89 | food_stuff_tp = fruits + vegetables + animal_products 90 | print("Tuple 1: ",fruits) 91 | print("Tuple 2: ",vegetables) 92 | print("Tuple 3: ",animal_products) 93 | print("Combined Foodstuff Tuples: ",food_stuff_tp) 94 | print("\n") 95 | 96 | #3 Change the about food_stuff_tp tuple to a food_stuff_lt list 97 | print("Number 3") 98 | food_stuff_lt = list(food_stuff_tp) 99 | print("Combined Foodstuff Lists: ",food_stuff_lt) 100 | print("\n") 101 | 102 | #4 Slice out the middle item or items from the food_stuff_tp tuple or food_stuff_lt list. 103 | print("Number 4") 104 | length_list = len(food_stuff_tp) 105 | if length_list % 2 == 1: 106 | startindex = ceil(length_list/2)-1 107 | endindex = startindex + 1 108 | else: 109 | startindex = ceil(length_list/2)-1 110 | endindex = startindex + 2 #endindex is not included 111 | print("List:",food_stuff_tp) 112 | print("Length:",len(food_stuff_tp)) 113 | print("Middle Food Tuple:",food_stuff_tp[startindex:endindex]) 114 | slicelist = list(food_stuff_tp) 115 | del slicelist[startindex:endindex] 116 | print("Sliced out Items: ",tuple(slicelist)) 117 | print("\n") 118 | 119 | 120 | #5 Slice out the first three items and the last three items from food_staff_lt list 121 | print("Number 5") 122 | slicelist = list(food_stuff_tp) 123 | del slicelist[0:3] 124 | print("Foodstuff Tuples: ",food_stuff_tp) 125 | print("With First 3 out:",tuple(slicelist)) 126 | print("\n") 127 | slicelist = list(food_stuff_tp) 128 | del slicelist[-3:] 129 | print("With Last 3 out:",tuple(slicelist)) 130 | print("\n") 131 | 132 | #6 Delete the food_staff_tp tuple completely 133 | print("Number 6") 134 | del food_stuff_tp 135 | try: 136 | print("Tuple with all items destroyed:",food_stuff_tp) 137 | except NameError as e: 138 | print("Tuple does not exist!") 139 | print (e) 140 | except: 141 | print("There is an error!") 142 | print("\n") 143 | 144 | #7 Check if an item exists in tuple: 145 | print("Number 7") 146 | nordic_countries = ('Denmark', 'Finland','Iceland', 'Norway', 'Sweden') 147 | country = 'Estonia' 148 | if country in nordic_countries: 149 | print(f'Yes, {country} exists in {nordic_countries}') 150 | else: 151 | print(f'No, {country} does not exists in {nordic_countries}') 152 | country = 'Iceland' 153 | if country in nordic_countries: 154 | print(f'Yes, {country} exists in {nordic_countries}') 155 | else: 156 | print(f'No, {country} does not exists in {nordic_countries}') 157 | print("\n") 158 | 159 | 160 | if __name__ == "__main__": 161 | main() 162 | -------------------------------------------------------------------------------- /Day 19/README.md: -------------------------------------------------------------------------------- 1 | # 💻 Lets Go!!🚀 🚀 🚀 2 | 3 | # 3️⃣0️⃣ Days of Python - Day One 4 | 5 | ## 📚 Table of Contents 6 | - [Objective](#objective) 7 | - [💻 Exercises - Day 19](#-exercises-day-19) 8 | - [Exercises: Level 1](#exercises-level-1) 9 | - [Exercises: Level 2](#exercises-level-2) 10 | - [Solution on Github](https://github.com/zidude1234/30_Days_of_Python/blob/main/Day%2019/Python%20Syntax/Day19%20Syntax.py) 11 | 12 | ## Objective 13 | This repository contains the solution for the Day Nineteen of the "30 Days of Python Challenge"! 14 | Thanks @Asabaneh for the excellent Python Content! 👋🏻 15 | 16 | 17 | ### 💻 Exercises: Day 19 18 | 19 | ### Exercises: Level 1 20 | 21 | 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: 22 | a) Read obama_speech.txt file and count number of lines and words 23 | b) Read michelle_obama_speech.txt file and count number of lines and words 24 | c) Read donald_speech.txt file and count number of lines and words 25 | d) Read melina_trump_speech.txt file and count number of lines and words 26 | 2. Read the countries_data.json data file in data directory, create a function that finds the ten most spoken languages 27 | 28 | ```py 29 | # Your output should look like this 30 | print(most_spoken_languages(filename='./data/countries_data.json', 10)) 31 | [(91, 'English'), 32 | (45, 'French'), 33 | (25, 'Arabic'), 34 | (24, 'Spanish'), 35 | (9, 'Russian'), 36 | (9, 'Portuguese'), 37 | (8, 'Dutch'), 38 | (7, 'German'), 39 | (5, 'Chinese'), 40 | (4, 'Swahili'), 41 | (4, 'Serbian')] 42 | 43 | # Your output should look like this 44 | print(most_spoken_languages(filename='./data/countries_data.json', 3)) 45 | [(91, 'English'), 46 | (45, 'French'), 47 | (25, 'Arabic')] 48 | ``` 49 | 50 | 3. Read the countries_data.json data file in data directory, create a function that creates a list of the ten most populated countries 51 | 52 | ```py 53 | # Your output should look like this 54 | print(most_populated_countries(filename='./data/countries_data.json', 10)) 55 | 56 | [ 57 | {'country': 'China', 'population': 1377422166}, 58 | {'country': 'India', 'population': 1295210000}, 59 | {'country': 'United States of America', 'population': 323947000}, 60 | {'country': 'Indonesia', 'population': 258705000}, 61 | {'country': 'Brazil', 'population': 206135893}, 62 | {'country': 'Pakistan', 'population': 194125062}, 63 | {'country': 'Nigeria', 'population': 186988000}, 64 | {'country': 'Bangladesh', 'population': 161006790}, 65 | {'country': 'Russian Federation', 'population': 146599183}, 66 | {'country': 'Japan', 'population': 126960000} 67 | ] 68 | 69 | # Your output should look like this 70 | 71 | print(most_populated_countries(filename='./data/countries_data.json', 3)) 72 | [ 73 | {'country': 'China', 'population': 1377422166}, 74 | {'country': 'India', 'population': 1295210000}, 75 | {'country': 'United States of America', 'population': 323947000} 76 | ] 77 | ``` 78 | 79 | ### Exercises: Level 2 80 | 81 | 4. Extract all incoming email addresses as a list from the email_exchange_big.txt file. 82 | 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 83 | 84 | ```py 85 | # Your output should look like this 86 | print(find_most_common_words('sample.txt', 10)) 87 | [(10, 'the'), 88 | (8, 'be'), 89 | (6, 'to'), 90 | (6, 'of'), 91 | (5, 'and'), 92 | (4, 'a'), 93 | (4, 'in'), 94 | (3, 'that'), 95 | (2, 'have'), 96 | (2, 'I')] 97 | 98 | # Your output should look like this 99 | print(find_most_common_words('sample.txt', 5)) 100 | 101 | [(10, 'the'), 102 | (8, 'be'), 103 | (6, 'to'), 104 | (6, 'of'), 105 | (5, 'and')] 106 | ``` 107 | 108 | 6. Use the function, find_most_frequent_words to find: 109 | 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) 110 | 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) 111 | 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) 112 | 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) 113 | 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 114 | 8. Find the 10 most repeated words in the romeo_and_juliet.txt 115 | 9. Read the [hacker news csv](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/hacker_news.csv) file and find out: 116 | a) Count the number of lines containing python or Python 117 | b) Count the number lines containing JavaScript, javascript or Javascript 118 | c) Count the number lines containing Java and not JavaScript 119 | 120 | [<< Day 18](../Day%2018/README.md) | [Day 20 >>](../Day%2020/README.md) 121 | 122 | 123 | --#### [Go to Top of Page](#objective) 124 | -------------------------------------------------------------------------------- /Day 21/Python Syntax/Day21 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day TwentyOne of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 28 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | # import the "re" module 16 | import re 17 | import collections 18 | import datetime 19 | from itertools import chain 20 | import json 21 | import csv 22 | import numpy 23 | import webbrowser 24 | import matplotlib 25 | import requests 26 | import statistics 27 | import pandas as pd 28 | from bs4 import BeautifulSoup 29 | 30 | 31 | def main(): 32 | os.system("cls") # clear console 33 | 34 | def p(num): 35 | print(f"Number {num}") 36 | 37 | def pn(num = 1): 38 | print(f"\n" * num) 39 | 40 | def bannergreeting(day_name,exercise_name): 41 | daybanner = f'Exercise {day_name} ' 42 | exercisebanner = f'Level {exercise_name} ' 43 | front_end = f'--' * 20 44 | return combinebanners(front_end,daybanner,exercisebanner) 45 | 46 | def combinebanners(s0,s1,s2): 47 | return s0 + s1 + s2 + s0 48 | 49 | class DataStats: 50 | def __init__ (self, list1 = [31, 26, 34, 37, 27, 26, 32, 32, 26, 27, 27, 24, 32, 33, 27, 25, 26, 38, 37, 31, 34, 24, 33, 29, 26]): 51 | self.data = list1 52 | 53 | def describe(self): 54 | return f''' 55 | Count: {self.count()} 56 | Sum: {self.sum()} 57 | Min: {self.min()} 58 | Max: {self.max()} 59 | Range: {self.range()} 60 | Mean: {self.mean():.2f} 61 | Median: {self.median()} 62 | Mode: {self.mode()} 63 | Standard Deviation: {self.std():.0f} 64 | Variance: {self.var():.2f} 65 | Frequency Distribution: 66 | {self.freq_dist()} 67 | ''' 68 | def __len(self): 69 | return self.count() 70 | 71 | def count(self): 72 | return len(self.data) 73 | 74 | def sum(self): 75 | return sum(self.data) 76 | 77 | def min(self): 78 | return min(self.data) 79 | 80 | def max(self): 81 | return max(self.data) 82 | 83 | def range(self): 84 | return max(self.data) - min(self.data) 85 | 86 | def mean(self): 87 | return statistics.mean(self.data) 88 | 89 | def median(self): 90 | return statistics.median(self.data) 91 | 92 | def mode(self): 93 | parameters,mode_list = ['mode','count'],[] 94 | temp = [] 95 | counttemp = [] 96 | dict_mode = {'mode': 0 ,'count' : 0 } 97 | if (len(statistics.multimode(self.data))==1): 98 | uni_mode = statistics.multimode(self.data) 99 | dict_mode['mode'] = uni_mode[0] 100 | dict_mode['count'] = self.data.count(uni_mode[0]) 101 | return dict_mode 102 | else: 103 | temp = statistics.multimode(self.data) 104 | counttemp = [self.data.count(i) for i in temp] 105 | mode_list.append(temp) 106 | mode_list.append(counttemp) 107 | dict_mode = list(zip(parameters,mode_list)) 108 | return dict_mode 109 | 110 | def std(self): 111 | return statistics.stdev(self.data) 112 | 113 | def var(self): 114 | return statistics.variance(self.data) 115 | 116 | def freq_dist(self): 117 | freq_list = [] 118 | freq_c1 = collections.Counter(self.data).items() 119 | freq_collection = [(_freq, _value) for (_value,_freq) in freq_c1] 120 | freq_tuple = sorted(freq_collection,key = lambda k:k , reverse = True) 121 | sumX = len(self.data) 122 | for i in freq_tuple: 123 | tp = (i[0] * 100/sumX,i[1]) 124 | freq_list.append(tp) 125 | s2 = f'Frequency distribution in percentage {freq_list}' 126 | return s2 127 | 128 | class PersonAccount: 129 | def __init__ (self, firstname='power', lastname='shell', income = {"Income1":250000,"Income2":20000,"Income3":3000}, expenses = {"Expense1":200000,"Expense2":5000,"Expense3":3000}): 130 | # self allows to attach parameter to the class 131 | self.firstname = firstname 132 | self.lastname = lastname 133 | self.income = income 134 | self.expenses = expenses 135 | 136 | def total_income(self): 137 | return sum(self.income.values()) 138 | 139 | def total_expenses(self): 140 | return sum(self.expenses.values()) 141 | 142 | def add_income(self): 143 | #self.income[new_income_tp[0]] = new_income_tp[1] 144 | pass 145 | 146 | def describe(self): 147 | return f''' 148 | Name {self.firstname} {self.lastname} 149 | Income {self.income} 150 | Expenses: {self.expenses} 151 | Total Income: {self.total_income()} 152 | Total Expenses: {self.total_expenses()} 153 | ''' 154 | 155 | # You can create a class called Statistics and create all the functions that do statistical calculations as methods for the Statistics class. 156 | ages = [31, 26, 34, 37, 27, 26, 32, 32, 26, 27, 27, 24, 32, 33, 27, 25, 26, 38, 37, 31, 34, 24, 33, 29, 26] 157 | 158 | # print('Count:', data.count()) # 25 159 | # print('Sum: ', data.sum()) # 744 160 | # print('Min: ', data.min()) # 24 161 | # print('Max: ', data.max()) # 38 162 | # print('Range: ', data.range() # 14 163 | # print('Mean: ', data.mean()) # 30 164 | # print('Median: ', data.median()) # 29 165 | # print('Mode: ', data.mode()) # {'mode': 26, 'count': 5} 166 | # print('Standard Deviation: ', data.std()) # 4.2 167 | # print('Variance: ', data.var()) # 17.5 168 | # print('Frequency Distribution: ', data.freq_dist()) # [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)] 169 | banner = bannergreeting 170 | print(banner(21,1)) 171 | 172 | data1 = DataStats() 173 | p(1) 174 | print(data1.describe()) 175 | pn() 176 | 177 | personTest = PersonAccount() 178 | p(2) 179 | print(personTest.describe()) 180 | pn() 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | if __name__ == "__main__": 190 | main() 191 | -------------------------------------------------------------------------------- /Day 07/Python Syntax/Day07 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Seven of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 06 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | 16 | #set uses curly braces also just like dicts but does not key:values 17 | # they are unordered 18 | #Converting list to set removes duplicates 19 | def main(): 20 | 21 | os.system("cls") # clear console 22 | it_companies = {'Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon'} 23 | A = {19, 22, 24, 20, 25, 26} 24 | B = {19, 22, 20, 25, 26, 24, 28, 27} 25 | age = [22, 19, 24, 25, 26, 24, 25, 24] 26 | 27 | s1 = 'Day 7 Exercise level 1' 28 | s2 = 'Day 7 Exercise level 2' 29 | s3 = 'Day 7 Exercise level 3' 30 | s0 = '' 31 | 32 | for i in range(20): 33 | s0 += "--" 34 | 35 | s = s0 + s1 + s0 36 | print(s) 37 | 38 | #1 Find the length of the set it_companies 39 | print("Number 1") 40 | print(len(it_companies)) 41 | print("\n") 42 | 43 | #2 Add 'Twitter' to it_companies 44 | print("Number 2") 45 | print("original set: ",it_companies) 46 | it_companies.add("Twitter") 47 | print("Adding twitter to set: ",it_companies) 48 | print("\n") 49 | 50 | #3 Insert multiple IT companies at once to the set it_companies - use update 51 | print("Number 3") 52 | print("original set: ",it_companies) #- add Netflix, Dell, Alibaba 53 | newset = set(("Netflix","Dell", "Alibaba","Amazon")) 54 | it_companies.update(newset) 55 | print("Adding new set to set - update removes duplicates: \n",it_companies) 56 | print("\n") 57 | 58 | #4 Remove one of the companies from the set it_companies 59 | print("Number 4") 60 | it_companies.remove("Netflix") 61 | print("Remove Netflix from set: ",it_companies) 62 | print("\n") 63 | 64 | 65 | #5 What is the difference between remove and discard 66 | print("Number 5") 67 | print("""The remove() method will 68 | raise an error if the specified item does not exist, 69 | and the discard() method will not.""") 70 | print("\n") 71 | 72 | s = s0 + s2 + s0 73 | print(s) 74 | 75 | #1 Join A and B 76 | print("Number 1") 77 | print("Set A: ",A) 78 | print("Set B: ",B) 79 | new_set = A.copy() 80 | new_set.update(B) 81 | print("A updated with B: ",new_set) 82 | new_set1 = A.copy() 83 | print("Method 2 using Union():", A.union(B)) 84 | print("\n") 85 | 86 | #2 Find A intersection B 87 | print("Number 2") 88 | print("Set A: ",A) 89 | print("Set B: ",B) 90 | new_set = A.intersection(B) 91 | print("A intersection B: ",new_set) 92 | print("\n") 93 | 94 | 95 | #3 Is A subset of B 96 | print("Number 3") 97 | print("Set A: ",A) 98 | print("Set B: ",B) 99 | new_set = A.copy() 100 | if new_set.issubset(B): 101 | print("A is a subset of B") 102 | elif B.issubset(new_set): 103 | print("B is a subset of A") 104 | else: 105 | print("No subset of each other") 106 | print("\n") 107 | 108 | #4 Are A and B disjoint sets 109 | print("Number 4") 110 | print("Set A: ",A) 111 | print("Set B: ",B) 112 | new_set = A.copy() 113 | if new_set.isdisjoint(B): 114 | print("A and B is disjoint") 115 | else: 116 | print("A and B is not disjoint") 117 | print("\n") 118 | 119 | #5 Join A with B and B with A 120 | print("Number 5") 121 | print("Set A: ",A) 122 | print("Set B: ",B) 123 | new_set = {} 124 | new_set = A.union(B) 125 | print("A joined with B: ",new_set) 126 | new_set = B.union(A) 127 | print("B joined with A: ",new_set) 128 | print("\n") 129 | 130 | #6 What is the symmetric difference between A and B 131 | # It means that it returns a set that contains all items from both sets, 132 | # except items that are present in both sets, mathematically: (A\B) ∪ (B\A) 133 | print("Number 6") 134 | print("Set A: ",A) 135 | print("Set B: ",B) 136 | new_set = {} 137 | new_set = A.symmetric_difference(B) 138 | print("A symmetric difference: ",new_set) 139 | print("Bonus:difference of A and B ",A.difference(B)) 140 | print("\n") 141 | print("The difference is an emppty set as A is contained within B") 142 | print("\n") 143 | # print("Number 2") 144 | # print("Set A: ",A) 145 | # print("Set B: ",B) 146 | # new_set = A.copy() 147 | # new_set.intersection(B) 148 | # print("A intersection B: ",new_set) 149 | # print("\n") 150 | 151 | #7 Delete the sets completely 152 | print("Number 7") 153 | del A 154 | del B 155 | try: 156 | print(f"Set A: ,{A} - Set B: ,{B}") 157 | except NameError as e: 158 | print("Set does not exist") 159 | print(e) 160 | print("\n") 161 | 162 | # Exercises: Level 3 163 | # Convert the ages to a set and compare the length of the list and the set, which one is bigger? 164 | # Explain the difference between the following data types: string, list, tuple and set 165 | # 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. 166 | 167 | 168 | s = s0 + s3 + s0 169 | print(s) 170 | 171 | #Convert the ages to a set and compare the length of the list and the set, which one is bigger? 172 | # Explain the difference between the following data types: string, list, tuple and set 173 | # "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. 174 | print("Number 1") 175 | age_list = [22, 19, 24, 25, 26, 24, 25, 24] 176 | age_set = set(age_list) #should remove duplicates 177 | print(f"Age Set: {age_set} \nAge List: {age_list}") 178 | if len(age_list) < len(age_set): 179 | print("Set is bigger") 180 | elif len(age_list) > len(age_set): 181 | print("List is bigger") 182 | else: 183 | print("Equal lengths") 184 | 185 | print("\n") 186 | 187 | print("Number 2") 188 | print("List items are ordered, changeable, allow duplicates and use square brackets") 189 | print("Tuple items are ordered, unchangeable, allow duplicates and use round brackets") 190 | print("Sets are unordered,unindexed, unchangeable, do not allow duplicates and use curly braces") 191 | print("Dicts are ordered,indexed with key names, changeable, do not allow duplicates and use curly braces") 192 | print("\n") 193 | 194 | 195 | print("Number 3") 196 | s = "I am a teacher and I love to inspire and teach people" 197 | liststring = s.split() 198 | print(liststring) 199 | set_string = set(liststring) 200 | print(f"Unique words in the string: {len(set_string)}\nTotal words in the sentence: {len(liststring)}") 201 | print("\n") 202 | 203 | if __name__ == "__main__": 204 | main() 205 | -------------------------------------------------------------------------------- /Day 09/Python Syntax/Day09 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Nine of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 07 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | # import the "re" module 16 | import re 17 | from math import ceil 18 | 19 | def main(): 20 | 21 | os.system("cls") # clear console 22 | 23 | s1 = 'Day 9 Exercise level 1' 24 | s2 = 'Day 9 Exercise level 2' 25 | s3 = 'Day 9 Exercise level 3' 26 | s0 = '' 27 | 28 | for i in range(20): 29 | s0 += "--" 30 | 31 | s = s0 + s1 + s0 32 | print(s) 33 | 34 | #1 Get user input using input(“Enter your age: ”). 35 | # If user is 18 or older, give feedback: You are old enough to drive. 36 | # If below 18 give feedback to wait for the missing amount of years. 37 | print("Number 1") 38 | age_cap = 18 39 | age = int(input("Enter your age:\n")) 40 | print('You are old enough to learn to drive.') if age > 18 else print (f'You need {age_cap - age} more years to learn to drive.') 41 | # first condition met, 'A is positive' will be printed 42 | print('\n') 43 | 44 | #2 Compare the values of my_age and your_age using if … else 45 | print("Number 2") 46 | age = int(input("Enter your age, I am 25:\n")) 47 | my_age = 25 48 | if age < my_age: 49 | print("You are 1 year younger than me") if my_age - age == 1 else print(f'You are {my_age - age} years younger than me.') 50 | elif age > my_age: 51 | print("You are 1 year older than me") if age - my_age == 1 else print(f'You are {age - my_age} years older than me.') 52 | else: 53 | print("We are equal in ages") 54 | print('\n') 55 | 56 | #3 Get two numbers from the user using input prompt. 57 | # If a is greater than b return a is greater than b, 58 | # if a is less b return a is smaller than b, else a is equal to b. 59 | print("Number 3") 60 | num1 = int(input("Enter number one:\n")) 61 | num2 = int(input("Enter number two:\n")) 62 | if num1 < num2: 63 | print(f'{num1} is smaller than {num2}') 64 | elif num1 > num2: 65 | print(f'{num1} is greater than {num2}') 66 | else: 67 | print(f'{num1} is equal to {num2}') 68 | print('\n') 69 | 70 | s = s0 + s2 + s0 71 | print(s) 72 | #1 Write a code which gives grade to students according to theirs scores: 73 | 74 | # 80-100, A 75 | # 70-89, B 76 | # 60-69, C 77 | # 50-59, D 78 | # 0-49, F 79 | 80 | print("Number 1") 81 | score = int(input("Enter the student score:\n")) 82 | if score in range(80,101): 83 | print(f'Your score: {score} has a grade of "A"') 84 | elif score in range(70,80): 85 | print(f'Your score: {score} has a grade of "B"') 86 | elif score in range(60,70): 87 | print(f'Your score: {score} has a grade of "C"') 88 | elif score in range(50,60): 89 | print(f'Your score: {score} has a grade of "D"') 90 | else: 91 | print(f'Your score: {score} has a grade of "F"') 92 | print('\n') 93 | 94 | print("Number 2") 95 | month = input("Enter the month of the year:\n") 96 | if month in ('September', 'October','November'): 97 | print(f'The month of : {month} is "Autumn"') 98 | elif month in ('December','January','February'): 99 | print(f'The month of : {month} is "Winter"') 100 | elif month in ('March', 'April','May'): 101 | print(f'The month of : {month} is "Spring"') 102 | elif month in ('June', 'July', 'August'): 103 | print(f'The month of : {month} is "Summer"') 104 | else: 105 | print(f'The month of : {month} does not exist!') 106 | print('\n') 107 | 108 | #3. The following list contains some fruits: 109 | # fruits = ['banana', 'orange', 'mango', 'lemon'] 110 | # If a fruit doesn't exist in the list add the fruit to the list and print the modified list. If the fruit exists print('That fruit already exist in the list') 111 | print("Number 3") 112 | fruits = ['banana', 'orange', 'mango', 'lemon'] 113 | #f1 = set(fruits) 114 | fr = input("Enter a fruit:\n") 115 | print("That fruit already exist in the list") if fr in fruits else fruits.append(fr) 116 | print("Updated fruit list:", fruits) 117 | print('\n') 118 | 119 | person = { 120 | 'first_name': 'Asabeneh', 121 | 'last_name': 'Yetayeh', 122 | 'age': 250, 123 | 'country': 'Finland', 124 | 'is_married': True, 125 | 'skills': ['JavaScript', 'React', 'Node', 'MongoDB', 'Python'], 126 | 'address': { 127 | 'street': 'Space street', 128 | 'zipcode': '02210' 129 | } 130 | } 131 | s = s0 + s3 + s0 132 | print(s) 133 | 134 | #1 Check if the person dictionary has skills key, if so print out the middle skill in the skills list. 135 | #2 Check if the person dictionary has skills key, if so check if the person has 'Python' skill and print out the result. 136 | #3 If a person skills has only JavaScript and React, print('He is a front end developer'), 137 | # if the person skills has Node, Python, MongoDB, print('He is a backend developer'), 138 | # if the person skills has React, Node and MongoDB, Print('He is a fullstack developer'), 139 | # else print('unknown title') - for more accurate results more conditions can be nested! 140 | #4 If the person is married and if he lives in Finland, print the information in the following format: 141 | print("Number 1") 142 | if person.get("skills"): 143 | print('skills exist') 144 | skill_list = person['skills'] 145 | length_list = len(skill_list) 146 | if length_list % 2 == 1: 147 | startindex = ceil(length_list/2)-1 148 | endindex = startindex + 1 149 | print("Middle skill:",str(skill_list[startindex:endindex])) 150 | else: 151 | startindex = ceil(length_list/2)-1 152 | endindex = startindex + 2 #endindex is not included 153 | print("Middle skills:",skill_list[startindex:endindex]) 154 | else: 155 | print("skills does not exist") 156 | print('\n') 157 | #print('skills exist') if person.get("skills") else print("skills does not exist") 158 | 159 | print("Number 2") 160 | if 'Python' in skill_list: 161 | print("Python is a skills present in the dictionary") 162 | else: 163 | print("Python is a skills NOT present in the dictionary") 164 | print('\n') 165 | 166 | print("Number 3") 167 | if skill_list == ["JavaScript","React"]: 168 | print("He is a front end developer") 169 | elif set(skill_list) == set(["Node", "Python", "MongoDB"]): 170 | print("He is a back end developer") 171 | elif set(skill_list) == set(( 'React', 'Node', 'MongoDB', 'Python','JavaScript',)): 172 | print("He is a full stack developer") 173 | else: 174 | print("Unknown Skillset") 175 | print('\n') 176 | 177 | print("Number 4") 178 | if person.get("is_married"): 179 | print(f"{person['first_name']} {person['last_name']} lives in {person['country']}. He is married") 180 | else: 181 | print("He is not married") 182 | print('\n') 183 | 184 | 185 | 186 | if __name__ == "__main__": 187 | main() 188 | 189 | -------------------------------------------------------------------------------- /Day 11/Python Syntax/Day11 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Eleven of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 12 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | from ast import arguments 9 | import sys 10 | # import the "os" module 11 | import os 12 | # import the "platform" module 13 | import platform 14 | # import the "platform" module 15 | import math 16 | # import the "re" module 17 | import re 18 | 19 | from formulalibrary import * 20 | 21 | def main(): 22 | os.system("cls") # clear console 23 | 24 | s1 = 'Day 11 Exercise level 1' 25 | s2 = 'Day 11 Exercise level 2' 26 | s3 = 'Day 11 Exercise level 3' 27 | s0 = '' 28 | 29 | for i in range(20): 30 | s0 += "--" 31 | 32 | s = s0 + s1 + s0 33 | print(s) 34 | 35 | def add_two_numbers(int1,int2): 36 | return int1 + int2 37 | 38 | #1. Declare a function add_two_numbers. It takes two parameters and it returns a sum. 39 | print("Number 1") 40 | num1 = int(input("Enter number one:\n")) 41 | num2= int(input("Enter number two:\n")) 42 | print(f'The sum of {num1} and {num2} is {add_two_numbers(num1,num2)}') 43 | print('\n') 44 | 45 | #2 using modules to clean up code 46 | # Write a function that calculates area_of_circle. 47 | print("Number 2") 48 | rad1 = int(input("Enter radius of circle:\n")) 49 | dim1= input("Enter dimension of circle(cm/m/km):\n") 50 | print(area_of_circle(rad1,dim1)) 51 | print('\n') 52 | 53 | #3 Write a function called add_all_nums which takes arbitrary number of arguments and sums all the arguments. 54 | # Check if all the list items are number types. If not do give a reasonable feedback. 55 | print("Number 3") 56 | tp_list1 = (8,3,5,7,'j') 57 | tp_list2 = ('gh',5,4,32,40,68,95) 58 | tp_list3 = (5,24,7,0,3,5,7,6,'[7]') 59 | 60 | print(add_all_nums(tp_list1)) 61 | print(add_all_nums(tp_list2)) 62 | print(add_all_nums(tp_list3)) 63 | 64 | print(add_all_nums(7,5,'j')) 65 | print('\n') 66 | 67 | #4 Write a function which converts °C to °F. 68 | print("Number 4") 69 | print(convert_celsius_to_fahrenheit(1000)) 70 | print(convert_celsius_to_fahrenheit('f')) 71 | print('\n') 72 | 73 | #5 Write a function called check-season, it takes a month parameter and returns the season: Autumn, Winter, Spring or Summer. 74 | print("Number 5") 75 | print(check_season('January')) 76 | print(check_season('January','April','Gregorian')) 77 | print('\n') 78 | 79 | #calculate_slope which return the slope of a linear equation 80 | print("Number 6") 81 | num1 = int(input("Enter the x-coefficient:\n")) 82 | num2 = int(input("Enter the y-intercept:\n")) 83 | print(slope(num1,num2)) 84 | print('\n') 85 | 86 | #Write a function which calculates solution set of a quadratic equation 87 | print("Number 7") 88 | print(solve_quadratic_eqn(1,7,10)) 89 | print('\n') 90 | 91 | #Declare a function named print_list. It takes a list as a parameter and it prints out each element of the list 92 | print("Number 8") 93 | print_list(list(tp_list1)) 94 | print('\n') 95 | 96 | #9 Declare a function named reverse_list. It takes an array as a parameter and it returns the reverse of the array (use loops) 97 | print("Number 9") 98 | print(reverse_list(list(tp_list1))) 99 | print('\n') 100 | 101 | #10 Declare a function named capitalize_list_items. It takes a list as a parameter and it returns a capitalized list of items 102 | list_words = ['bETTer beliEVE','cOLD COLd HeART', 'pEACHES in Georgia','sACrifICe'] 103 | print("Number 10") 104 | print(f'The capitalised form of the list {list_words} is \n {capitalize_list_items(list_words)}') 105 | print('\n') 106 | 107 | #11 Declare a function named add_item. It takes a list and an item parameters. It returns a list with the item added at the end. 108 | print("Number 11") 109 | list_mo_hits = [] 110 | list_mo_hits = capitalize_list_items(list_words) 111 | print(add_items(list_mo_hits,"Take My Breath")) 112 | print('\n') 113 | 114 | #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 115 | print("Number 12") 116 | print(remove_item(food_stuff, 'Mango')) 117 | print(remove_item(numbers, 3)) 118 | print(remove_item(numbers, 10)) 119 | print('\n') 120 | 121 | #13 Declare a function named sum_of_numbers. It takes a number parameter and it adds all the numbers in that range. 122 | print("Number 13") 123 | print(sum_all_numbers(5)) # 15 124 | print(sum_all_numbers(10)) # 55 125 | print(sum_all_numbers(100)) # 5050 126 | print('\n') 127 | 128 | #14 Declare a function named sum_of_odds. It takes a number parameter and it adds all the odd numbers in that range. 129 | print("Number 14") 130 | print(sum_odd_numbers(5)) # 9 131 | print(sum_odd_numbers(10)) # 25 132 | print(sum_odd_numbers(100)) # 2500 133 | print('\n') 134 | 135 | #15 Declare a function named sum_of_even. It takes a number parameter and it adds all the even numbers in that - range. 136 | print("Number 15") 137 | print(sum_even_numbers(5)) # 6 138 | print(sum_even_numbers(10)) # 30 139 | print(sum_even_numbers(100)) # 2550 140 | print('\n') 141 | 142 | s = s0 + s2 + s0 143 | print(s) 144 | 145 | 146 | #1 Declare a function named evens_and_odds . It takes a positive integer as parameter and 147 | # it counts number of evens and odds in the number. 148 | # print(evens_and_odds(100)) 149 | # The number of odds are 50. 150 | # The number of evens are 51. 151 | print("Number 1") 152 | print(evens_and_odds(100)) 153 | 154 | #2 Call your function factorial, it takes a whole number as a parameter and it return a factorial of the number 155 | print("Number 2") 156 | print(my_factorial(5)) 157 | print("\n") 158 | 159 | #3 Call your function is_empty, it takes a parameter and it checks if it is empty or not 160 | print("Number 3") 161 | 162 | s = '' 163 | listnew = [] 164 | b = NULL 165 | d = 25 166 | e = ["5",6,9] 167 | list_check = list((s,listnew,b,d,e)) 168 | print(list_check) 169 | print(is_empty(list_check)) 170 | print("\n") 171 | 172 | print("Number 4") 173 | listdata = [4,3,5,8,'i'] 174 | print_statistics(my_statistics(listdata)) 175 | listdata2 = [4,3,5,8,5] 176 | print_statistics(my_statistics(listdata2)) 177 | 178 | s = s0 + s3 + s0 179 | print(s) 180 | #1. Write a function called is_prime, which checks if a number is prime. 181 | print("Number 1") 182 | print(numberIsPrime(121)) 183 | print('\n') 184 | 185 | #2 Write a functions which checks if all items are unique in the list. 186 | print("Number 2") 187 | print(listIsUnique(listdata2)) 188 | listdata3 = ['1',2,1,"The dog flew over the moon",7,"The dog flew over the moon"] 189 | print(listIsUnique(listdata3)) 190 | print(listIsUnique(listdata)) 191 | print('\n') 192 | 193 | #3 Write a function which checks if all the items of the list are of the same data type. 194 | print(sameListType(listdata)) 195 | print(sameListType(listdata2)) 196 | 197 | #4 Write a function which check if provided variable is a valid python variable 198 | var_name = input("Enter desired variable name:\n") 199 | print(checkValidvariable(var_name)) 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | if __name__ == "__main__": 246 | main() 247 | -------------------------------------------------------------------------------- /Day 05/Day05 Solution.txt: -------------------------------------------------------------------------------- 1 | @:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:Exercise level 1@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@: 2 | Number 1 3 | [] 4 | 5 | 6 | Number 2 7 | ['Name', 'Age', 3, 465, 'Country', 'City', 'Asabeneh', 250, ['Halo', 'Mario Bros', 'Street Fighter'], ('Coding', 'For', 'All')] 8 | 9 | 10 | Number 3 11 | listOne Length :10 12 | 13 | 14 | Number 4 15 | first item :Name 16 | last item :('Coding', 'For', 'All') 17 | Middle item with index (5) : City 18 | 19 | 20 | Number 5 21 | ['dataBio', 99, '3.2m', 'Complicated', '50 Git Street'] 22 | 23 | 24 | Number 6 25 | List Declared 26 | 27 | 28 | Number 7 29 | ['Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon'] 30 | 31 | 32 | Number 8 33 | Company 1: Facebook 34 | Company 2: Google 35 | Company 3: Microsoft 36 | Company 4: Apple 37 | Company 5: IBM 38 | Company 6: Oracle 39 | Company 7: Amazon 40 | 41 | Number 9 42 | first company :Facebook 43 | middle company :Apple 44 | last company :Amazon 45 | 46 | 47 | New List: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon'] 48 | 49 | Number 9 50 | first company :Facebook 51 | middle company :Apple 52 | last company :Amazon 53 | 54 | 55 | Number 10 56 | New List: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon'] 57 | 58 | 59 | Number 11 60 | Updated List: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon', 'Dell'] 61 | 62 | 63 | Number 12 64 | Updated List: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'HP', 'IBM', 'Oracle', 'Amazon', 'Dell'] 65 | 66 | 67 | Number 13 68 | Uppercase List: ['METAVERSE', 'GOOGLE', 'MICROSOFT', 'APPLE', 'HP', 'IBM', 'ORACLE', 'AMAZON', 'DELL'] 69 | 70 | Number 14 71 | Itcompanies: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'HP', 'IBM', 'Oracle', 'Amazon', 'Dell', '#;'] 72 | 73 | 74 | Number 15 75 | HP item is at index: 4 76 | 77 | 78 | Number 16 79 | Unsorted: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'HP', 'IBM', 'Oracle', 'Amazon', 'Dell', '#;'] 80 | Sorted: ['#;', 'Amazon', 'Apple', 'Dell', 'Google', 'HP', 'IBM', 'Metaverse', 'Microsoft', 'Oracle'] 81 | 82 | Number 17 83 | Unsorted: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'HP', 'IBM', 'Oracle', 'Amazon', 'Dell', '#;'] 84 | Reverse Sorted: ['Oracle', 'Microsoft', 'Metaverse', 'IBM', 'HP', 'Google', 'Dell', 'Apple', 'Amazon', '#;'] 85 | 86 | Number 18 87 | Slice: ['Metaverse', 'Google', 'Microsoft'] 88 | 89 | 90 | Number 19 91 | Slice: ['Amazon', 'Dell', '#;'] 92 | 93 | Number 20 94 | List: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'HP', 'IBM', 'Oracle', 'Amazon', 'Dell', '#;'] 95 | Middle Company(s): ['HP', 'IBM'] 96 | 97 | Number 21 98 | Original List: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'HP', 'IBM', 'Oracle', 'Amazon', 'Dell', '#;'] 99 | ['Google', 'Microsoft', 'Apple', 'HP', 'IBM', 'Oracle', 'Amazon', 'Dell', '#;'] 100 | 101 | Number 22 102 | Original List: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'HP', 'IBM', 'Oracle', 'Amazon', 'Dell', '#;'] 103 | Even list with middle removed: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'Oracle', 'Amazon', 'Dell', '#;'] 104 | 105 | Number 23 106 | Original List: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'HP', 'IBM', 'Oracle', 'Amazon', 'Dell', '#;'] 107 | List with last item removed: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'HP', 'IBM', 'Oracle', 'Amazon', 'Dell'] 108 | 109 | 110 | Number 24 111 | Original List: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'HP', 'IBM', 'Oracle', 'Amazon', 'Dell', '#;'] 112 | List with all items removed: [] 113 | 114 | Number 25 115 | Original List: ['Metaverse', 'Google', 'Microsoft', 'Apple', 'HP', 'IBM', 'Oracle', 'Amazon', 'Dell', '#;'] 116 | List does not exist! 117 | local variable 'modifiedlist' referenced before assignment 118 | 119 | Number 26 120 | Front End ['HTML', 'CSS', 'JS', 'React', 'Redux'] 121 | Back End ['Node', 'Express', 'MongoDB'] 122 | Front End Extended ['HTML', 'CSS', 'JS', 'React', 'Redux', 'Node', 'Express', 'MongoDB'] 123 | 124 | Number 27 125 | Original Full Stack: ['HTML', 'CSS', 'JS', 'React', 'Redux', 'Node', 'Express', 'MongoDB'] 126 | Final Full Stack: ['HTML', 'CSS', 'JS', 'React', 'Redux', 'Python', 'SQL', 'Node', 'Express', 'MongoDB'] 127 | 128 | @:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:Exercise level 2@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@:@: 129 | Number 1 130 | Original Age List : [19, 22, 19, 24, 20, 25, 26, 24, 25, 24] 131 | a1. Sorted Full Stack: [19, 19, 20, 22, 24, 24, 24, 25, 25, 26] 132 | a2. Max value - Full Stack: 26 133 | a3. Min value - Full Stack: 19 134 | b. With Min and Max ages added: [19, 19, 20, 22, 24, 24, 24, 25, 25, 26, 19, 26] 135 | c. Median age: 24.0 136 | d. Average age: 22.75 137 | e. range of age: 26 - 19 = 7 138 | f. absolute of min less average is : 3.75, compared to absolute of max less average of 3.25 139 | 140 | Number 2A 141 | Middle Country(ies): ['Lesotho'] 142 | 143 | 144 | Number 2B 145 | First List has 97 items: ['Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bhutan', 'Bolivia', 'Bosnia and Herzegovina', 'Botswana', 'Brazil', 'Brunei', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Central African Republic', 'Chad', 'Chile', 'China', 'Colombi', 'Comoros', 'Congo (Brazzaville)', 'Congo', 'Costa Rica', "Cote d'Ivoire", 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'East Timor (Timor Timur)', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Fiji', 'Finland', 146 | 'France', 'Gabon', 'Gambia, The', 'Georgia', 'Germany', 'Ghana', 'Greece', 'Grenada', 'Guatemala', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Honduras', 'Hungary', 'Iceland', 'India', 'Indonesia', 147 | 'Iran', 'Iraq', 'Ireland', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Korea, North', 'Korea, South', 'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lebanon', 'Lesotho'] 148 | 149 | 150 | 151 | Second List has 96 items: ['Liberia', 'Libya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Mauritania', 'Mauritius', 'Mexico', 'Micronesia', 'Moldova', 'Monaco', 'Mongolia', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Qatar', 'Romania', 'Russia', 'Rwanda', 'Saint Kitts and Nevis', 'Saint Lucia', 'Saint Vincent', 'Samoa', 'San Marino', 'Sao Tome and Principe', 'Saudi Arabia', 'Senegal', 'Serbia and Montenegro', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'Spain', 'Sri Lanka', 'Sudan', 'Suriname', 'Swaziland', 'Sweden', 'Switzerland', 'Syria', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', 'Togo', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Vatican City', 'Venezuela', 'Vietnam', 'Yemen', 'Zambia', 'Zimbabwe'] 152 | 153 | Number 2C 154 | ch: China 155 | ru: Russia 156 | usa: USA 157 | scandic countries: ['Finland', 'Sweden', 'Norway', 'Denmark'] 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | -------------------------------------------------------------------------------- /Day 19/Python Syntax/Day19 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Nineteen of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 22 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | from importlib.resources import path 9 | import sys 10 | # import the "os" module 11 | import os 12 | # import the "platform" module 13 | import platform 14 | # import the "platform" module 15 | import math 16 | # import the "re" module 17 | import re 18 | import collections 19 | import datetime 20 | from itertools import chain 21 | import json 22 | import csv 23 | 24 | def main(): 25 | os.system("cls") # clear console 26 | 27 | def p(num): 28 | print(f"Number {num}") 29 | 30 | def pn(num = 1): 31 | print(f"\n" * num) 32 | 33 | def bannergreeting(day_name,exercise_name): 34 | daybanner = f'Exercise {day_name} ' 35 | exercisebanner = f'Level {exercise_name} ' 36 | front_end = f'--' * 20 37 | return combinebanners(front_end,daybanner,exercisebanner) 38 | 39 | def combinebanners(s0,s1,s2): 40 | return s0 + s1 + s2 + s0 41 | 42 | def topten_languages(country_data, num_lang=5): 43 | list_lang = [] 44 | for data in country_data: 45 | lang_count = data["languages"] 46 | list_lang.append(lang_count) 47 | list_flat = [i for level1 in list_lang for i in level1] 48 | lang_collection = collections.Counter(list_flat) 49 | top10_lang_collection = lang_collection.most_common(num_lang) 50 | print(f'The {num_lang} most common lanaguages are;') 51 | for i in top10_lang_collection: 52 | print(i) 53 | return "" 54 | 55 | def topten_pop(country_data, num_countries=10): 56 | list_lang_country_pop,templist = [],[] 57 | for data in country_data: 58 | keyitems = ['name',"languages","population"] 59 | lang_count_pop = {k:data[k] for k in keyitems} 60 | templist.append(lang_count_pop) 61 | list_lang_country_pop = sorted(templist, key = lambda k: k["population"], reverse=True) 62 | print(f'The {num_countries} most populated countries are;') 63 | for i in list_lang_country_pop[0:num_countries]: 64 | print(i) 65 | return "" 66 | 67 | def top_words_in_english(fname, num_extract = 5): 68 | filename = "".join([newpath,fname]) 69 | f1 = open(filename) 70 | all_text = f1.read() 71 | seperate_words = list(filter(None,re.split('\s+|\.',all_text))) 72 | words_group = collections.Counter(seperate_words) 73 | w_tp = words_group.items() 74 | w_tp2 = [(b,a) for (a,b) in w_tp] 75 | w_tuple = sorted(w_tp2,key = lambda k:k[0],reverse=True) 76 | return w_tuple[0:num_extract] 77 | 78 | def compare_files_for_similarity(fileX,fileY): 79 | temp1 = open(fileX) 80 | file1 = list(filter(None,re.split('\s+|\.',temp1.read()))) 81 | temp1.close() 82 | temp2 = open(fileY) 83 | file2 = list(filter(None,re.split('\s+|\.',temp2.read()))) 84 | dict1 = {x : file1.count(x) for x in file1} 85 | dict2 = {x : file2.count(x) for x in file2} 86 | similars = set(file1).intersection(set(file2)) 87 | rate1 = sum(dict1[w] for w in similars)/len(file1) 88 | rate2 = sum(dict2[w] for w in similars)/len(file2) 89 | print("The rate of similarity is: ", rate1*rate2*100, '%') 90 | print("The similar words are: ", similars) 91 | return '' 92 | 93 | banner = bannergreeting 94 | print(banner(19,1)) 95 | 96 | #1 Write a function which count number of lines and number of words in a text. 97 | # a) Read obama_speech.txt file and count number of lines and words 98 | # b) Read michelle_obama_speech.txt file and count number of lines and words 99 | # c) Read donald_speech.txt file and count number of lines and words 100 | # d) Read melina_trump_speech.txt file and count number of lines and words 101 | 102 | p(1) 103 | #python file is in Day19/Python Syntax folder 104 | #data file is in Day19/data folder 105 | 106 | fulldir = os.path.dirname(__file__) 107 | rootdir = fulldir.rsplit('\\',1) 108 | newpath=rootdir[0]+'\\data\\' 109 | 110 | _obamapath = "".join([newpath,'obama_speech.txt']) 111 | _michpath = "".join([newpath,'michelle_obama_speech.txt']) 112 | _trumppath = "".join([newpath,'donald_speech.txt']) 113 | _melapath = "".join([newpath,'melina_trump_speech.txt']) 114 | #1A 115 | f1 = open(_obamapath) 116 | Lines = f1.readlines() #All Lines 117 | Linenum = 0 118 | for linetext in Lines: 119 | Linenum +=1 120 | filename = _obamapath.rsplit('\\',1)[1] 121 | print(f"{filename} has {Linenum} lines") 122 | f1.close() 123 | 124 | f2 = open(_michpath) 125 | Lines = f2.readlines() #All Lines 126 | Linenum = 0 127 | for linetext in Lines: 128 | Linenum +=1 129 | filename = _michpath.rsplit('\\',1)[1] 130 | print(f"{filename} has {Linenum} lines") 131 | f2.close() 132 | 133 | f3 = open(_trumppath) 134 | Lines = f3.readlines() #All Lines 135 | Linenum = 0 136 | for linetext in Lines: 137 | Linenum +=1 138 | filename = _trumppath.rsplit('\\',1)[1] 139 | print(f"{filename} has {Linenum} lines") 140 | f3.close() 141 | 142 | 143 | f4 = open(_melapath) 144 | Lines = f4.readlines() #All Lines 145 | Linenum = 0 146 | for linetext in Lines: 147 | Linenum +=1 148 | filename = _melapath.rsplit('\\',1)[1] 149 | print(f"{filename} has {Linenum} lines") 150 | f4.close() 151 | pn(2) 152 | p(2) 153 | with open('country_data.json') as file_object: 154 | c_data = json.loads(json.load(file_object)) 155 | print(topten_languages(c_data,3)) 156 | print(topten_languages(c_data,10)) 157 | file_object.close() 158 | 159 | pn() 160 | p(3) 161 | #3 Read the countries_data.json data file in data directory, create a function that creates a list of the ten most populated countries 162 | print(topten_pop(c_data,3)) 163 | print(topten_pop(c_data,10)) 164 | 165 | #4 Extract all incoming email addresses as a list from the email_exchange_big.txt file. 166 | p(4) 167 | _email_exchangepath = "".join([newpath,'email_exchanges_big.txt']) 168 | emailpattern = '^From.[\w([\w\.]+\s?\w*\+?@\w+\.?\w*\.?\w*\.?\w*' #from emails 169 | 170 | 171 | with open(_email_exchangepath) as file_object: 172 | Lines = file_object.readlines() 173 | List_emails,str_response_from = [],'' 174 | linenum = 0 175 | for linetext in Lines: 176 | from_emails = re.findall(emailpattern2,linetext) 177 | linenum += 1 178 | if from_emails: 179 | s2 = f"'From Email' noted on line {linenum} : {from_emails}" 180 | str_response_from += s2 + '\n' 181 | with open("from_emails.txt",'w+') as file_object1: 182 | file_object1.write(str_response_from) 183 | file_object1.close() 184 | file_object.close() 185 | 186 | p(5) 187 | print(top_words_in_english('obama_speech.txt', 10)) 188 | pn() 189 | 190 | p(6) 191 | print(top_words_in_english('donald_speech.txt', 10)) 192 | print(top_words_in_english('melina_trump_speech.txt', 10)) 193 | print(top_words_in_english('michelle_obama_speech.txt', 10)) 194 | pn() 195 | 196 | p(7) 197 | print(compare_files_for_similarity(_michpath,_melapath)) 198 | pn() 199 | 200 | p(8) 201 | print(top_words_in_english('romeo_and_juliet.txt', 10)) 202 | pn() 203 | 204 | p(9) 205 | strings_list = ['"Python or python"','"JavaScript or javaScript or javascript"','"Java"'] 206 | stringlist = ['[P|p]ython','([J|j]avaScript|[J|j]avascript)',r'\bJava\b'] #regex pattern 207 | _hackerpath = "".join([newpath,'hacker_news.csv']) 208 | for i in stringlist: 209 | searchstring = strings_list[stringlist.index(i)] 210 | linecount, linestring = 0,0 211 | with open(_hackerpath) as hackerfile: 212 | csv_data = csv.reader(hackerfile,delimiter = ',') 213 | for row in csv_data: 214 | linecount +=1 215 | rowstring = ', '.join(row) 216 | if(re.findall(i,rowstring)): 217 | linestring +=1 218 | print(f'Hackerfile has {linecount} rows with {searchstring} found in {linestring} lines.') 219 | 220 | 221 | 222 | if __name__ == "__main__": 223 | main() 224 | -------------------------------------------------------------------------------- /Day 03/Python Syntax/Day03 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day Three of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 03 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | # import the "re" module 16 | import re 17 | # import the "functools" module to get the reduce function 18 | from functools import reduce 19 | 20 | def main(): 21 | 22 | os.system("cls") # clear console 23 | 24 | #1 25 | myage = 21 26 | 27 | #2 28 | myheight = 2.15 29 | 30 | #3 31 | mycomplex = 4 + 7j 32 | 33 | #4 34 | print("Number 4") 35 | tri_base = int(input("Enter the base:\n")) 36 | tri_height = int(input("Enter the height:\n")) 37 | tri_area = tri_base * tri_height/2 38 | print("The area of the triangle is ",int(tri_area)) 39 | print("\n") 40 | 41 | #5 42 | print("Number 5") 43 | tri_side_a = int(input("Enter side a:\n")) 44 | tri_side_b = int(input("Enter side b:\n")) 45 | tri_side_c = int(input("Enter side c:\n")) 46 | tri_peri = tri_side_a + tri_side_b + tri_side_c 47 | print("The perimeter of the triangle is ",int(tri_peri)) 48 | print("\n") 49 | 50 | 51 | #6 52 | print("Number 6") 53 | rect_len = int(input("Enter the rectangle length:\n")) 54 | rect_width = int(input("Enter the rectangle width:\n")) 55 | rect_area = rect_len * rect_width 56 | print("The area of the rectangle is ",int(rect_area)) 57 | 58 | rect_peri = (rect_len + rect_width) *2 59 | print("The perimeter of the rectangle is ",int(rect_peri)) 60 | print("\n") 61 | 62 | #7 63 | print("Number 7") 64 | circ_radius = int(input("Enter the radius of the circle:\n")) 65 | circ_area = math.pi * circ_radius **2 66 | circ_peri = math.pi * circ_radius * 2 67 | print("The area of the circle is " + "{:.2f}".format(circ_area)) 68 | print("The circumference of the circle is " + "{:.2f}".format(circ_peri)) 69 | print("\n") 70 | 71 | #8 72 | print("Number 8") 73 | print("For the line equation y = 2x - 2") 74 | slope8 = 2 75 | y = 0 76 | x_int8 = (y + 2)/2 77 | 78 | x = 0 79 | y_int8 = 2*x -2 80 | print("The slope of the equation ",slope8) 81 | print("X intercept ",x_int8) 82 | print("Y intercept ",y_int8) 83 | print("\n") 84 | 85 | #9 86 | print("Number 9") 87 | myString1 = "The Slope of points{} and {} equals {}" 88 | myString2 = "The Euclidian distance between points{} and {} equals {}" 89 | 90 | point1 = (2, 2) 91 | point2 = (6, 10) 92 | slope_9 = (point2[1]-point1[1]) /(point2[0]-point1[0]) 93 | euclid_dist = ((math.pow(point2[1]-point1[1],2) + math.pow(point2[0]-point1[0],2))**0.5) 94 | print(myString1.format(point1,point2,"{:.2f}".format(slope_9))) 95 | print(myString2.format(point1,point2,"{:.2f}".format(euclid_dist))) 96 | print("\n") 97 | 98 | 99 | 100 | #10 101 | print("Number 10") 102 | if slope8 == slope_9: 103 | print("The slopes are equal") 104 | else: 105 | print("The slopes are unequal") 106 | print("\n") 107 | #11 108 | print("Number 11") 109 | check_key = 1 110 | try: 111 | x_value = int(input("Enter x value for the quadratic equation (y = x^2 + 6x + 9)\n")) 112 | except: 113 | print("Enter a valid integer") 114 | x_value = int(input("Enter x value for the quadratic equation (y = x^2 + 6x + 9)\n")) 115 | y_value = x_value **2 + 6*x_value + 9 116 | print ("The value of y is ",y_value) 117 | print("The next step is to iterate to find the x value where y value is zero") 118 | while (check_key == 1): 119 | try: 120 | x_value = int(input("Enter x value for the quadratic equation (y = x^2 + 6x + 9)\n")) 121 | except: 122 | print("Enter a valid integer") 123 | x_value = int(input("Enter x value for the quadratic equation (y = x^2 + 6x + 9)\n")) 124 | 125 | y_value = x_value **2 + 6*x_value + 9 126 | if (y_value == 0): 127 | check_key = 0 128 | print("The value at which y is zero is", x_value) 129 | else: 130 | print ("The value of y is " + str(y_value) + ", this is not equal to zero") 131 | print("\n") 132 | #12 133 | print("Number 12") 134 | str1, str2 = 'python','dragon' 135 | if len(str1)==len(str2): 136 | print(len(str1)==len(str2)) 137 | else: 138 | print(len(str1)==len(str2)) 139 | print("\n") 140 | #13 141 | print("Number 13") 142 | x = re.search("on", str1) 143 | y = re.search("on", str2) 144 | if x and y: 145 | print("\"on\" appears in both " + str1 + " and " + str2) 146 | print("\n") 147 | #14 148 | print("Number 14") 149 | str4 = 'I hope this course is not full of jargon' 150 | if 'jargon' in str4: 151 | print("'jargon' found in \"" + str4 + "\"") 152 | else: 153 | print("jargon not found in \"" + str4 + "\"") 154 | print("\n") 155 | #15 156 | print("Number 15") 157 | if 'on' in str1 and 'on' in str2: 158 | print("'on' found in \"" + str1 + " and " + str2) 159 | else: 160 | print("'on' not found in \"" + str1 + " and " + str2) 161 | print("\n") 162 | #16 163 | print("Number 16") 164 | print("length of '"+ str1 + "' is:", len(str1)) 165 | print("In float length of '"+ str1 + "' is:", float(len(str1))) 166 | print("In string length of '"+ str1 + "' is:", str(float(len(str1)))) 167 | print("\n") 168 | #17 169 | print("Number 17") 170 | for i in range (1,11): 171 | result = ' is even' if i % 2 == 0 else ' is odd' 172 | #print(str(i) + result) - append strings 173 | print(f"{i} {result}") #- formatted string literals 174 | #18 175 | print("Number 18") 176 | #Check if the floor division of 7 by 3 is equal to the int converted value of 2.7. 177 | if (7//3 == int(2.7)): 178 | print('floor division of 7 by 3 is equal to the int converted value of 2.7') 179 | else: 180 | print("not equal") 181 | print('\n') 182 | 183 | #19 184 | print("Number 19") 185 | #Check if type of '10' is equal to type of 10 186 | if (type('10') == type(10)): 187 | print('Types "10" and 10 are equal') 188 | else: 189 | print('Types "10" and 10 are not equal') 190 | print('\n') 191 | 192 | #20 193 | print("Number 20") 194 | #Check if int('9.8') is equal to 10 195 | #this will throw an error as floating strings cannot be cast into integer 196 | #int("9") will work 197 | try: 198 | x = int('9.8') 199 | if x == 10: 200 | print(f"{int('9.8')} is equal to {10}") 201 | except ValueError as e: 202 | print("Decimal strings cannot be made into int") 203 | print("\'int('9.8')\' is not equal to {10}") 204 | except: 205 | print("\'int('9.8')\' is not equal to {10}") 206 | print('\n') 207 | 208 | #21 209 | print("Number 21") 210 | person_hours = int(input("Enter hours:\n")) 211 | person_rate = int(input("Enter rate per hour:\n")) 212 | print(f"Your weekly earning is {person_rate * person_hours}") 213 | print("\n") 214 | 215 | #22 216 | print("Number 22") 217 | person_years = int(input("Enter number of years you have lived:\n")) 218 | print(f"You have lived for {person_years * 365 * 24 * 3600} seconds.") 219 | print("\n") 220 | 221 | #23 222 | print("Number 23") 223 | for i in range (1,6): 224 | listRange = list((i,1,i,i**2,i **3)) 225 | print(listRange) 226 | print("\n") 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | if __name__ == "__main__": 236 | main() 237 | 238 | #"D:/Program Files/Python/Python310/python.exe" "d:/Home Documents/DEVELOPMENT/GIT/30_Days_of_Python/Day 03/Python Syntax/Day03 Syntax.py 239 | -------------------------------------------------------------------------------- /Day 01/Python Syntax/Day01 Syntax.py: -------------------------------------------------------------------------------- 1 | #Day One of the 30 Day Challenge 2 | # Introduction 3 | # Author: dataBio 4 | # Date: 01 Feb 2022 5 | # IDE: VSCode 6 | 7 | # import the "sys" module 8 | import sys 9 | # import the "os" module 10 | import os 11 | # import the "platform" module 12 | import platform 13 | # import the "platform" module 14 | import math 15 | 16 | def main(): 17 | 18 | os.system("cls") # clear console 19 | s1 = 'Exercise level 1' 20 | s2 = 'Exercise level 2' 21 | s3 = 'Exercise level 3' 22 | 23 | s0 = codeString = '' 24 | codeString =''' 25 | #Helloworld code of the 30 Day Challenge 26 | # Introduction 27 | # Author: dataBio 28 | # Date: 01 Feb 2022 29 | # IDE: VSCode 30 | 31 | # import the "sys" module 32 | import sys 33 | # import the "os" module 34 | import os 35 | # import the "platform" module 36 | import platform 37 | # import the "platform" module 38 | import math 39 | def main(): 40 | #1. Print the python version details 41 | print("Python version", sys.version) 42 | print("Version info.",sys.version_info) 43 | 44 | #Bonus 45 | print('Bonus -- Python Platfrom version',platform.python_version()) 46 | 47 | 48 | #2. Simple Operations 49 | #Define multiline variables a = 3 and b = 4 50 | a , b = 3, 4 51 | myString = "{} {} {} equals {}" 52 | 53 | #addition operation 54 | print ("a. Addition Operation: " + myString.format(a,'+',b, a+b)) 55 | #subtraction operation 56 | print ("b. Subtraction Operation: " + myString.format(a,'-',b, a-b)) 57 | #Multiply operation 58 | print ("c. Multiply Operation: " + myString.format(a,'*',b, a*b)) 59 | #Modulo operation 60 | print ("d. Modulo Operation: " + myString.format(a,'%',b, a%b)) 61 | #Division operation 62 | print ("e. Division Operation: " + myString.format(a,'/',b, a/b)) 63 | #Exponent operation 64 | print ("f1. Exponent Operation: " + myString.format(a,'**',b, a**b)) 65 | #Floor Division operation 66 | print ("g. Floor Division Operation: " + myString.format(a,'//',b, a//b)) 67 | 68 | #Bonus - Exponent operation (import math module) 69 | print ("f2. 'Bonus -- Exponent Operation: " + myString.format(a,'pow',b, math.pow(a,b))) 70 | 71 | 72 | #3. Strings 73 | #Greeting 74 | intro = 'Hello, My Name is ' 75 | enjoy = 'I am enjoying 30 days of Python.' 76 | 77 | 78 | string1 = input("Please input your first name:" 79 | ) 80 | 81 | string2 = input("Please input your last name:") 82 | 83 | 84 | string3 = input("Please input your country") 85 | 86 | 87 | print( intro + string1 + " " + string2 + " from " + 88 | string3 + "." + enjoy) 89 | 90 | #4. Data Types 91 | #Assign data from variables a to h 92 | a, b, c, d, e, f, g, h = 10, 9.8, 3.14, 4 - 4j, ['Asabeneh', 'Python', 'Finland'],string1, string2, string3 93 | #use type(x) 94 | myString2 = "Data: {} is of data type:- {}" 95 | print (myString2.format(a,type(a))) 96 | print (myString2.format(b,type(b))) 97 | print (myString2.format(c,type(c))) 98 | print (myString2.format(d,type(d))) 99 | print (myString2.format(e,type(e))) 100 | print (myString2.format(f,type(f))) 101 | print (myString2.format(g,type(g))) 102 | print (myString2.format(h,type(h))) 103 | 104 | 105 | if __name__ == "__main__": 106 | main()''' 107 | 108 | 109 | myint = 5 110 | myfloat = 13.2 111 | mycomplex = -2 + 6j 112 | mystr = "This is a string" 113 | mybool = True 114 | mylist = [0, 1, "two", 3.2, False] 115 | mytuple = (0, 1, 2) 116 | myset = {"one", "two" , 2, 3 + 2j} 117 | mydict = {"one" : 1, "two" : 2} 118 | 119 | for i in range(20): 120 | s0 += "@:" 121 | 122 | s = s0 + s1 + s0 123 | 124 | print(s) 125 | #1. Print the python version details 126 | print("Python version", sys.version) 127 | print("Version info.",sys.version_info) 128 | print('\n') 129 | #Bonus 130 | print('Bonus -- Python Platfrom version',platform.python_version()) 131 | 132 | print('\n') 133 | #2. Simple Operations 134 | #Define multiline variables a = 3 and b = 4 135 | a , b = 3, 4 136 | myString = "{} {} {} equals {}" 137 | 138 | #addition operation 139 | print ("a. Addition Operation:\t" + myString.format(a,'+',b, a+b)) 140 | #subtraction operation 141 | print ("b. Subtraction Operation:\t" + myString.format(a,'-',b, a-b)) 142 | #Multiply operation 143 | print ("c. Multiply Operation:\t" + myString.format(a,'*',b, a*b)) 144 | #Modulo operation 145 | print ("d. Modulo Operation:\t" + myString.format(a,'%',b, a%b)) 146 | #Division operation 147 | print ("e. Division Operation:\t" + myString.format(a,'/',b, a/b)) 148 | #Exponent operation 149 | print ("f1. Exponent Operation:\t" + myString.format(a,'**',b, a**b)) 150 | #Floor Division operation 151 | print ("g. Floor Division Operation:\t" + myString.format(a,'//',b, a//b)) 152 | 153 | #Bonus - Exponent operation (import math module) 154 | print ("f2. 'Bonus -- Exponent Operation:\t" + myString.format(a,'pow',b, math.pow(a,b))) 155 | print('\n') 156 | 157 | #3. Strings 158 | #Greeting 159 | intro = 'Hello, My Name is ' 160 | enjoy = 'I am enjoying 30 days of Python.' 161 | 162 | 163 | string1 = input("Please input your first name:\n") 164 | string2 = input("Please input your last name:\n") 165 | string3 = input("Please input your country\n") 166 | 167 | print( intro + string1 + " " + string2 + " from " + 168 | string3 + "." + enjoy) 169 | 170 | #4. Data Types 171 | #Assign data from variables a to h 172 | a, b, c, d, e, f, g, h = 10, 9.8, 3.14, 4 - 4j, ['Asabeneh', 'Python', 'Finland'],string1, string2, string3 173 | #use type(x) 174 | myString2 = "Data: {} is of data type:-\t{}" 175 | print (myString2.format(a,type(a))) 176 | print (myString2.format(b,type(b))) 177 | print (myString2.format(c,type(c))) 178 | print (myString2.format(d,type(d))) 179 | print (myString2.format(e,type(e))) 180 | print (myString2.format(f,type(f))) 181 | print (myString2.format(g,type(g))) 182 | print (myString2.format(h,type(h))) 183 | 184 | #'''Create a folder named day_1 inside 30DaysOfPython folder. Inside day_1 folder, 185 | # create a python file helloworld.py and repeat questions 1, 2, 3 and 4. 186 | # Remember to use print() when you are working on a python file. Navigate to the directory where you have saved your file, and run it.''' 187 | 188 | s = s0 + s2 + s0 189 | print(s) 190 | current_path_string = os.path.dirname( __file__ ) 191 | #find the index of the last '\' 192 | tempnum = current_path_string.rfind("\\") 193 | tempstr = "" 194 | #extract the string up till that index 195 | for i in range(tempnum): 196 | tempstr += current_path_string[i] 197 | 198 | #Tempstr is up one Directory 199 | #navigate to it 200 | os.chdir(tempstr) 201 | #create a new path for the Hello World Folder and file 202 | 203 | foldername = "HelloWorld Folder" 204 | try: 205 | os.makedirs(foldername) 206 | print("Directory " , foldername , " Created ") 207 | except FileExistsError: 208 | print("Directory " , foldername , " already exists") 209 | 210 | newpath = os.path.join(tempstr, foldername) 211 | os.chdir(newpath) 212 | myfile = open("hello.world.py","w+") 213 | myfile.write(codeString) 214 | myfile.close() 215 | 216 | # Write an example for different Python data types such as Number(Integer, Float, Complex), String, Boolean, List, Tuple, Set and Dictionary. 217 | 218 | s = s0 + s3 + s0 219 | print(s) 220 | 221 | print (myString2.format(myint,type(myint))) 222 | print (myString2.format(myfloat,type(myfloat))) 223 | print (myString2.format(mycomplex,type(mycomplex))) 224 | print (myString2.format(mystr,type(mystr))) 225 | print (myString2.format(mybool,type(mybool))) 226 | print (myString2.format(mylist,type(mylist))) 227 | print (myString2.format(mytuple,type(mytuple))) 228 | print (myString2.format(myset,type(myset))) 229 | print (myString2.format(mydict,type(mydict))) 230 | 231 | # Find an Euclidian distance between (2, 3) and (10, 8) 232 | myString3 = "The Euclidian distance between points{} and {} equals {}" 233 | point1 = (2, 3) 234 | point2 = (10, 8) 235 | euclid_dist = ((math.pow(point2[1]-point1[1],2) + math.pow(point2[0]-point1[0],2))**0.5) 236 | print(myString3.format(point1,point2,"{:.2f}".format(euclid_dist))) 237 | 238 | 239 | if __name__ == "__main__": 240 | main() 241 | --------------------------------------------------------------------------------