Posts

Showing posts from August, 2021

How to perform calculations with fractions or number's in Python

Image
Performing mathematical calculations with integers and floating-point numbers is easy in Python.  Rounding Numerical Values: Problem: You want to round a floating-point number to a fixed number of decimal places. Solution: For simple rounding, use the built-in round(value, ndigits) function.   When a value is exactly halfway between two choices, the behavior of round is to round to the nearest even digit. That is the values such as 1.5 or 2.5 both get rounded to 2.   The number of digits given to round() can be negative, in which case rounding takes a place for tens, hundreds, thousands, and so on.    For example :   a = 1627731   print( round(a, -1))   print(round(a, -2))   print(round(a, -3))   Output:   1627730   1627700   1628000   Don’t confuse rounding with formatting a value for output. If your goal is simply to output a numerical value with a certain number of decimal places, you don’t typically need to use round(). Instead, just specify the desired precision when formatting. F

Web Scraping using BeautifulSoup library.

Image
  What is it a Beautifulsoup library? Beautiful Soup  is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree. To install Beautifulsoup: pip install bs4 What is the requests library? The  library is the de facto standard for making HTTP requests in Python. It abstracts the complexities of making requests behind a beautiful, simple API so that you can focus on interacting with services and consuming data in your application. To install requests: pip install requests What is the html5lib library? html5lib is a pure python library for parsing HTML. It is designed to conform to the WHATWG HTML specification, as is implemented by all major web browsers.    To install html5lib: pip install html5lib Steps: Installing the required third-party libraries. Accessing the HTML content from the webpage. Parsing the HTML content. Searching and navigating through the parse