Skip to content

Repo for storing codes for "100 Days of Code - The Complete Python Pro Bootcamp for 2021" Udemy course by Dr. Angela Yu

Notifications You must be signed in to change notification settings

yanjun91/Python100DaysCodeBootcamp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python 100 Days Code Bootcamp

Repo for storing codes for "100 Days of Code - The Complete Python Pro Bootcamp for 2021" Udemy course by Dr. Angela Yu

Day 1:

Replit Links:

What I learnt:

  • print() and input() functions
  • concatenating strings and using \n as a way to break line
  • simple debugging
  • NameError exception

Day 2

Replit Links:

What I learnt:

  • Use ** as exponential
  • Use type() to check data type
  • Type casting (eg.: str(), int(), float())
  • TypeError exception
  • Using floor division // to calculate floor value in int type (eg.: 8 // 3 output is 2 instead of 2.666..)
  • Shorthand operators (eg.: x += 1 equals to x = x + 1)
  • f string format able to auto cast various data types into string (eg.: print(f"Your score is {score}) where score is a variable in int data type)
  • Mathematics functions (eg.: round(2.34567, 2) become 2.35, however round(2.3, 2) will still be 2.3)
  • Using {number:.2f} in f-string to round off and format to 2 decimal places even the number to be round off has lesser decimal places
    • Where:
      • : introduces the format spec
      • 0 enables sign-aware zero-padding for numeric types
      • .2 sets the precision to 2
      • f displays the number as a fixed-point number

Day 3

Replit Links:

What I learnt:

  • Indentation is important to let Python know which code is under which block
  • Modulo operation will result in the remainder of a division. (eg.: 2%3 is equal to 1)
  • if/elif/else
  • logical operators
  • convert to lowercase characters using .lower() (eg.: "Yan Jun".lower() becomes yan jun)
  • count a character in string using .count(). Note that it is case sensitive. (eg.: "Yan Jun".count("a") is equal to 1)
  • Using ''' to wrap around multi-line strings to be printed out

Day 4

Replit Links:

What I learnt:

  • Creating/using modules
  • Generating random integers and float
  • IndexError
  • Using flow chart to visualize the logic flow before start coding for better implementation

Day 5

Replit Links:

What I learnt:

  • for loops
  • use range(begin, end, [step]), where the end number is not included, to loop instead of a list
  • using random.choice(list) and random.shuffle(list)

Day 6

Replit/Reeborg Links:

What I learnt:

Day 7

Replit Links:

What I learnt:

  • Reminded to draw a flowchart before starting to code a complex solution
  • Code the solution one step at a time instead of doing it all in once and debug later which may caused longer time to fix
  • Add a print statement while coding to test
  • Use if 'x' in string to check for character x in a string
  • creating and importing modules

Day 8

Replit Links:

What I learnt:

  • Definition of parameters and argument
    • parameter is the variable used to accepts value in function (i.e.: name in def greet(name))
    • argument is the value passed in when calling function (i.e.: greet("Yan Jun") where "Yan Jun" is the argument)
  • Positional argument is argument that we passed into function in the order
  • Keyword argument is used to specified which parameter that the argument should assigned to
  • Using modulus to loop within the length of list to ensure index wont go out of bound

Day 9

Replit Links:

What I learnt:

  • Dictionary is a list of key-value pairs where the key can be of any primitive type like string or int
  • Nesting of dictionaries and/or lists within another dictionary/list
  • Using for loop on dictionary yields key instead of its value

Day 10

Replit Links:

What I learnt:

  • Can have multiple return statements in a function but only one that is first processed runs

  • Use docstrings to document the function which then will be shown as a description of function when autocomplete

    • To add docstrings, surround the description using """ that is typed directly after definition of function, within the function's code block.
    • """ can be used as multiline comments as well but not recommended
  • Function can be used as values in dictionary. We can then used it as describe below:

    1. Define a function
    def my_function(x, y):
      return z
    1. Define dictionary
    dict = { 
      "function": my_function 
    }
    1. Use the function in dictionary
    function = dict["function"]
    function(x, y)
  • Recursion: Calling the a function within the same function

Day 11

Replit Links:

What I learnt:

  • modularize functions for better code organization and easier to manage
  • work on functionalities one part at a time

Day 12

Replit Links:

What I learnt:

Day 13

Replit Links:

What I learnt:

  • Use print or debugger to debug your code

Day 14

Replit Links:

What I learnt:

  • Breaking down large task into smaller chunks and tackle them one by one

Day 15

What I learnt:

  • Properly go through requirement before start to code.

Day 16

What I learnt:

  • Object Oriented Programming = OOP
  • An object has attributes and methods
  • Go to pypi.org to see all available modules
  • Using prettytable module to pretify table

Day 17

What I learnt:

  • Use PascalCase for class name and snake_case for variables
  • constructor name is def __init__(self):
  • Try to only accepts input from caller in methods in class instead of doing something like accessing items in list directly

Day 18

What I learnt:

  • Read documentation to better understand the uses of methods in modules
  • Use alias by adding as like so, import turtle as t
  • Tuple is fixed(a.k.a. immutable) and cant be changed while list can. Use list(my_tuple) to convert tuple to list

Day 19

What I learnt:

  • Creating different instances so that each of them are acting independently

Day 20

What I learnt:

  • using screen.tracer(0) together with screen.update() and time.delay(0.1) to control the refresh rate of the turtle object

Day 21

What I learnt:

  • Inheritance. Uses code below to inherit Animal class to Fish class, where super refer to the Animal class. We can also override a method from superclass by defining the same method name in subclass.
    class Fish(Animal):
      def __init__(self):
        super().__init()
  • Slicing. We can get a subset from a list/tuples and assign to another list.
    • For example, to get [c, d, e] from alphabets = [a, b, c, d, e, f, g], we would use `alphabets[2:5]'.
    • We can also use alphabets[2:] to get [c, d, e, f, g]
    • Using alphabets[:5] results in getting [a, b, c, d, e]
    • alphabets[2:5:2] will get [c, e] while using alphabets[::2] would get [a, c, e, g].
    • Use alphabets[::-1] to reverse the list

Day 22

What I learnt:

  • Using onkeypress() to continuously move the turtle on holding down a key

Day 23

What I learnt:

  • Need to think out of the box in creating solutions

Day 24

What I learnt:

  • read, write, append files
  • absolute file path starts from root that starts with /
  • relative file path starts with current folder (working directory) that starts with ./ while using ../ is one step up to parent directory
  • Use forward slash regardless of Mac or Windows

Day 25

What I learnt:

  • using pandas as a way to go through data structures easily and read/write files
  • can add image to turtle window as background but only accepts gif type image

Day 26

What I learnt:

  • List comprehension can be used in the format of new_list = [new_item for item in list]
  • Conditional list comprehension can be used in the format of new_list = [new_item for item in list if test]
  • Dictionary comprehension can be used in the format of new_dict = {new_key:new_value for (key,value) in dict.items()}
  • Conditional dictionary comprehension can be used in the format of new_dict = {new_key:new_value for (key,value) in dict.items() if test}
  • loop through data frame using comprehension: {new_key:new_value for (index, row) in df.iterrows()}

Day 27

What I learnt:

  • Using tkinter module to build a GUI
  • we can put default value to parameters of function when defining it which renders them optionals
    • def my_function(a=1, b=2, c=3): then we can call without pass in any arguments
  • we can add unlimited number of arguments by using *args as parameter like below
    def add(*args):
      total = 0
      for n in args:
          total += n
      return total
  • use **kwargs as parameter in a function definition as keyword arguments where arguments are in key-value pair
    def calculate(n, **kwargs):
      print(kwargs)
      n += kwargs["add"]
      n *= kwargs["multiply"]
      print(n)
    
    calculate(2, add=3, multiply=5)
  • We can define our own class constructor with **kw.
    class Car:
      def __init__(self, **kw):
          # self.make = kw["make"]
          # self.model = kw["model"]
          # Using .get() so that it just return None instead of error if the specific argument not specified when call
          self.make = kw.get("make")
          self.model = kw.get("model")
    
    my_car = Car(make="Nissan")
    print(my_car.make)
  • the parameter name args and kwargs in *args and **kwargs respectively can change to other name. The number of asterisk is the one that determine whether it is a unlimited arguments or keyword argument

Day 28

What I learnt:

  • Adding image using canvas
  • using windows.after(1000, some_function, x) to call some_function function with x as argument after 1 second
  • dynamic typing concept in python means we can change the type of a variable when we change it, say, from int to str and it still work
    a = 4  # int type
    a = "Hi"  # str type
    # a changes from int type to str type

Day 29

What I learnt:

  • Entry.delete(0, END) will clear the entry of string from index 0 to end of string
  • The code below will yield an input entry of "123yanjun@email.com". The first parameter indicates the index to insert the text. Using END will insert to the end of string.
    email_entry.insert(0, "yanjun@email.com")
    email_entry.insert(0, "123")

Day 30

What I learnt:

  • catch exception syntax format:
  try:
    # your own logic that might cause exception
  except:
    # execute logic here if there was an exception
  else:
    # execute logic here if no exception
  finally:
    # no matter what happen, execute logic here
  • we can raise exception by using raise. For example: raise TypeError("This is an error that I made up.") which includes our own message
  • Json functions
    • Write: json.dump(), it will convert into json format as well
    • Read: json.load(), which will serialized into dict type
    • Update: json.update()

Day 31

What I learnt:

  • updating text, image in canvas
  • more understanding on using window.after()

Day 32

What I learnt:

  • Sending email using Python through SMTP
  • Use msg="Subject:Hello\n\nThis is the body of my email" as the sendmail() parameter to specify the email subject "Hello" and email body by adding \n\n
  • Use pythonanywhere to host python code in the cloud

Day 33

What I learnt:

  • Use requests module to call API
  • Response codes meaning in plain text:
    • 1XX: Hold On
    • 2XX: Here You Go
    • 3XX: Go Away
    • 4XX: You Screwed Up
    • 5XX: I Screwed Up
  • HTTP Status reference: https://httpstatuses.com/

Day 34

What I learnt:

  • We can define data type for the variables/parameter upfront using format variable: data_type. For example, age: int. In class or function, we just put it in parentheses when defining it
  • We can also define the return type of function using -> data_type format. For example, def check_price(price: int) -> bool: would return a bool type

Day 35

What I learnt:

  • Sending SMS alert using Python through Twilio

Day 36

What I learnt:

  • Combining all knowledge on calling API and sending SMS to build a small project

Day 37

What I learnt:

  • Request types:
    • GET: requests.get() => get data from API
    • POST: requests.post() => give data to API
    • PUT: requests.put() => update data through API
    • DELETE: requests.delete() => delete data through API
  • Using pixela to track habits through their APIs

Day 38

What I learnt:

  • Combined knowledge learnt in previous lessons.

Day 39 & 40

What I learnt:

  • Go through API documentation for info on how to use the API

Day 41

What I learnt:

  • How Internet works
  • Basic elements of HTML tags

Day 42

What I learnt:

  • Tables, Forms elements
  • Can host a website free in github
    1. Create a repository
    2. Upload html files
    3. Go to Settings > Github Pages section
    4. At Source, choose master branch from the dropdown and click Save.
    5. It may take some time to publish the website. The link to the website will be shown at the Github Pages section.

Day 43

What I learnt:

  • Using inline, internal and external CSS to style HTML pages.
  • Different way to style elements in HTML pages by using tags/class/id selectors.

Day 44

What I learnt:

  • Box model of div tag
  • display block elements takes up the whole width of the page regardless of content, but height still determine by content. However, we can change the width of them using CSS.
    • Common block elements: <p>, <h1>...<h6>, <div>, <ol>, <ul>, <li> and <form>
  • display inline elements does not take up whole width of page but just the size that it needs only.
    • Common inline elements: <span>, <img> and <a>
  • inline-block is hybrid of both block and inline. We can change it's width and can put inline with several elements.
  • static position is the original position that those elements would be without any css.
  • relative position is the position moved from the original static position(aka relative to the original static position). We would generally use relative position with some positioning css property. The element with relative position will not affect other element so it might overlap other element if we move it.
  • Example below shows the img element move 30px to the right from it's original static position:
img {
	position: relative;
	left: 30px;
}
  • abosulte position will move its position relative to its parent element. This will affect flow of other elements.
  • fixed position will stick to a position relative to its parents even when we scroll the page.
  • text-align used in a parent element will center everything for its child elements. Use margin: 0 auto to center if block display element has some width.
  • 100% or 1em font-size is equivalent to 16px. Recommend to use 1rem so that in case parent element as font size set to 2em or more then it wont stack.
  • Google font css link import: https://fonts.google.com/
  • Free flaticons: https://www.flaticon.com/
  • Color palettes: https://colorhunt.co/
  • CSS Button creator: https://cssbuttoncreator.com/
  • Extra challenge can be done at https://www.frontendmentor.io/

Day 45

What I learnt:

  • Using BeautifulSoup module to scrap website
  • Reads the robots.txt of the website(if available) to check which pages are allow/disallow to scrap and how long is the delay we should crawl. We can access the file by adding "/robots.txt" after the website root domain.

Day 46

What I learnt:

  • Scrap Billboard top 100 tracks and create a Spotify playlist from it.

Day 47

What I learnt:

  • Scrap Amazon website to track price fluctuation and email when current price is below target price.

Day 48

What I learnt:

  • Using Selenium to automate website testing
  • Using Selenium to get certain elements content by id, class, name, css selector(eg: anchor tag within div), etc
  • Can use get element by name to fill in forms
  • If all else method to get an element wont work, then can use xpath
  • We can combine each item from 2 lists into a dict within a list using list comprehension
    • list = [{"key1": value1, "key2": value2} for value1 in list1 for value2 in list2]

Day 49

What I learnt:

  • Save jobs from Linkedin search result automatically using Selenium

Day 50

What I learnt:

  • Built a Tinder auto swipe bot

Day 51

What I learnt:

  • Built a bot to automatically test Internet speed and tweet when speed not as promised

Day 52

What I learnt:

  • Built a bot to automatically follow followers from an Instagram page.

Day 53

What I learnt:

  • Built rental web scraping automation using BeautifulSoup to scrap data and Selenium to enter data to Google Form

Day 54

What I learnt:

  • Flask and Django is framework for Python on the web backend to process business logic
  • Basic unix commands
    • Use rm -rf <FolderName>: -rf means recursively forcibly. All files and directory inside that folder will be removed.
  • __name__ will have the current class/function/method/descriptor/generator name
    • If we run that specific Python file, then the __name__ will be __main__ -@app.route('/') is a decorator function. Whatever function definition under it will be triggered with additional functionalities defined in app.route.

Day 55

What I learnt:

  • Run in debug mode by adding debug=True in app.run() like so, app.run(debug=True)
  • We can specify the path variable to certain data types like int. If that particular variable is of a different type, say string, then it will render as 404 not found.

Day 56

What I learnt:

  • html files goes into templates folder
  • static files goes into static folder
  • can execute a Javascript code in developer tools' console to make the webpage editable on the page itself. Use document.body.contentEditable=true

Day 57

What I learnt:

  • Use Jinja to template webpage content dynamically
  • Use {{ <Python Code> }} in html file to render python codes
  • pass in dynamic content using **kwargs in render_template() as parameter. render_template("index.html", key=value)
  • use {% %} for multiline python code in html file and add {% endfor %} or {% endif %} depending on the code.
  • use {{ url_for('<function_name>') }} in html file inside href to navigate to the page
    • we can even add parameters to the use_for() method to pass in the params for the URL. For example, if we are to add num as part of the url as params then use this: {{ url_for('<function_name>', num = 3) }}

Day 58

What I learnt:

  • Using Bootstrap to style web page.
  • z-index only takes effect when we use position property
  • Hierarchy of applying css styles from most important to least important: inline css > internal css > id > class > elements
  • try not to use id unless necessary even if the element only appear once. Use id on sections only.
  • bad practice to use inline css style

Day 59

What I learnt:

  • Enhanced day 55 blogpost website with bootstrap

Day 60

What I learnt:

  • Add POST request functionality to blog's contact me page
  • use request module from Flask to receive POST/GET request from a form submission

Day 61

What I learnt:

  • Use WTForms and Flask-Bootstrap to build page with form with lesser code

Day 62

What I learnt:

  • Use WTForms and Flask-Bootstrap work on more exercise to add form submission to save data to csv

Day 63

What I learnt:

  • Build a website with sqlite as database and using SQLAlchemy to access the database.

Day 64

What I learnt:

  • Create top 10 movies with Flask/SQLAlchemy/WTForms

Day 65

What I learnt:

  • Web Design is important to deliver the mood and message as intended.
    • Red: Love, Energy, Intensity
    • Yellow: Joy, Intellect, Attention
    • Green: Freshness, Safety, Growth
    • Blue: Stability, Trust, Serenity
    • Purple: Royalty, Wealth, Feminity
  • Use analogous color (colors besides each other in color palette wheel) works well together. Good for navigation bar and body of website, logo and its background. Not good for standing out.
  • Use complementary color (colors opposite each other in color palette wheel) to makes something pop but do not use them as your font color and background color.
  • Use sans-serif and serif in title and body in turn. Use Humanist typeface for easier reading.
  • Emotion behind fonts
    • Serif gives traditional, stable and respectable feels. Use in a more professional settings like letter.
    • Sans-serif gives sensible, simple and straightforward mood. Many startup likes to use this in their website.
    • Script gives personal, creative and elegant feels.
    • Display gives friendly, loud and amusing mood.
    • Modern gives stylish, chic and smart feels. Used in style magazines.
  • Big item often draws attention. Use it for things that you want to attract attention like Checkout button.
  • Layout of website is important. Don't use all words only, add some pictures/different colors and font size. Use 40-60 characters per line for easier eye tracking to read
  • Align text properly. Reduce number of alignment points.
  • Spacing is important. Luxury store often spaces out their items. If items are cluttered together, it will look like discount store.
  • Think about audience and consider design based on them. Children audience will like more colorful design.
  • UX:
    • Simple
    • Consistency
    • Reading patterns start left to right but the length to look through from left to right is shorten as user goes down the webpage. Or use Z pattern.
    • Design challenges: https://www.dailyui.co/
    • Website to create design for free: https://www.canva.com/

Day 66

What I learnt:

  • Building REST API using Python with Flask

Day 67

What I learnt:

  • Update blog webpage to use sqlite

Day 68

What I learnt:

  • Add authentication to a page and encrypt password before store in database.

Day 69

What I learnt:

  • Add authentication + password encryption to previous blog post website project.
  • Add blog post admin feature
  • Add comment feature

Day 70

What I learnt:

  • GitHub lessons
  • Deploy previous blog website project to Heroku

Day 71

What I learnt:

  • Using Pandas DataFrame to do data exploration
  • .head() and .tail() to view the top 5 and bottom 5 rows respectively
  • Can use .findna() to find NaN data and use .dropna() to drop rows with NaN data
  • Use df['column name'][index] or df['column name'].loc(index) to access the column data for that particular index
  • Use .max() and .min() to get the max or min value for that column(e.g.: df['Salary'].max())
  • Use .idxmax() and .idxmin() to get the max and min index respectively
  • Use .sort_values() to sort the dataframe. Use parameter ascending=False to sort it by descending order
  • Use .insert() to insert column into dataframe. Need to specify the index to insert and the data in array with the same order
  • Use .groupby() to group the rows by columns specified
  • Google Colaboratory Notebook link: https://colab.research.google.com/drive/1_oNsxiRzdc1tqIrFiiMfSjt_ldB4w6Qt?usp=sharing

Day 72

What I learnt:

  • Plotting chart with matplotlib
  • can convert string to datetime using pandas.to_datetime() for easier plotting
  • reshaped DataFrame using .pivot()
  • fill in NaN values with 0 in all columns using .fillna(0, inplace=True)
  • using plot() with loop to plot multiple lines in chart using "label" parameter in plot() method
  • add legend after adding label
  • smooth out the line using .rolling() and .mean()
  • Google Colaboratory Notebook link: https://colab.research.google.com/drive/1B6sxOG4ufmNa-AotFc5PCmvFdUlZl0CI

Day 73

What I learnt:

  • Using df.agg() to aggregate data
  • Use df[:-2] to slice out the last 2 data in data frame
  • Use df.rename() to rename columns in DataFrame
  • To create two-axes chart, need to create the axes first then use .plot()
ax1 = plt.gca() # get current axes
ax2 = ax1.twinx() 

Day 74

What I learnt:

  • use .describe() to quickly see some descriptive statistics at a glance
  • use .resample() to change the period of a time-series chart. The column with date/time need to be first converted to datetime using pd.to_datetime()
  • use linestyles parameter in .plot() to change the line styles to something like dashed line or dotted lines
  • use .grid() to draw grids to chart
  • Google Colaboratory Notebook link: https://colab.research.google.com/drive/1VrYYysKKSY_xitnLI8xr_20tYuWLE2Bj

Day 75

What I learnt:

  • Using .sample(n) to sample a few random data with n rows
  • Find duplicated entries using .duplicated() and use .drop_duplicates() to remove duplicated rows. Additional parameters can be entered for more precise removal of duplicates based on columns.
  • Use .to_numeric() to convert to numeric values
  • Use plotly to ploy pie, donut, bar chart, box plots and scatter plots
  • Google Colaboratory Notebook link: https://colab.research.google.com/drive/12FYqAekf0NZu5R2cj9b9egEM938d6rKc

Day 76

What I learnt:

  • Create arrays manually using np.array([1,2,3,4,5]) from NumPy module
  • Generate array using .arange() with specified range and .linspace() with specified range plus the size of array that has the numbers difference equally spread apart.
  • analyse multi-dimensional/n-dimensional array(ndarray)
  • slice and get subset of ndarray
  • scalar and matrix multiplication operation with ndarray
  • manipulate color of image that is composed from ndarray
  • Google Colaboratory Notebook link: https://colab.research.google.com/drive/1JhImou6hK_hopEyj0qH5ioBIPzMfBDFB

Day 77

What I learnt:

  • Filter Pandas DataFrames based on multiple conditions using both .loc[] and .query()
  • Create bubble chart using Seaborn module
  • Seaborn created bubble chart can be styled using Matplotlib as it Seaborn built upon Matplotlib
  • Use floor division to convert years to decades decades = years//10*10
  • Use Seaborn to superimpose a linear regressions over our data
  • Run regressions with scikit-learn and calculate the coefficients.
  • Google Colaboratory Notebook link: https://colab.research.google.com/drive/1wTVYymYQHe2J1YKu67pnsoNy_wuta4gE

Day 78

What I learnt:

Day 79

What I learnt:

  • use histograms to visualise distributions
  • superimpose histograms on top of each other even when the data series have different lengths
  • use a to smooth out kinks in a histogram and visualise a distribution with a Kernel Density Estimate (KDE)
  • improve a KDE by specifying boundaries on the estimates
  • use scipy and test for statistical significance by looking at p-values
  • highlight different parts of a time series chart in Matplotib
  • add and configure a Legend in Matplotlib
  • Use NumPy's .where() function to process elements depending on a condition.
  • Google Colaboratory Notebook link: https://colab.research.google.com/drive/1qLmI7qJLBZbx2v-PfXvZZpAxLMKNATYf

Day 80

What I learnt:

Day 81 - 100

  • Assignments

About

Repo for storing codes for "100 Days of Code - The Complete Python Pro Bootcamp for 2021" Udemy course by Dr. Angela Yu

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published