Unit 7: Problem Solving Real World Programming Problems
Unit 7: Problem Solving Real World Programming Problems
Problem Solving
• Real world programming problems
Weather Forecasting
Code Implementation
• We will be needing the requests library of
python, which we need to install in the
system using the pip command in the CMD
of your computer.
Now, we have the basic stuff ready and we are all set to move to
the major part of the project. We will start off by importing
the requests module that we just installed in our system earlier.
import requests
• We will create a function that will take the name of the city
the user enters and prints the report for us. Look at the code
of the function below.
Frequency in Python
• We often use loops to print the count of
each element in the list or so. But, we can
also use the counter from the collections
module to print out the count of each
element in the input data.
• For this you have to import
collections module offered by python
Let’s see how it works.
String Formatting
• Commonly, we use loops to iterate over the list and print out
the elements in it. But, we will see how we can quickly iterate
over multiple lists and print out the elements in them.
• Using pandas is the easiest way to read and write a CSV file.
But, you should also be aware of this method, where we use
base python to read and write CSV files.
Regular Expression (Regex)
What is a package?
• Complex tasks are better solved step by step, one subtask at
a time. That's why programmers create and use modules, or
sets of related code saved in separate files and aimed at
solving specific tasks.
• When you have many different modules, you'll definitely want
to group and organize them. A Python package is a directory
of a collection of modules. Just as you organize your
computer files into folders and sub-folders, you can organize
modules into packages and sub-packages.
• Each package should contain a file named __init__.py. This
file usually includes the initialization code for the
corresponding package.
NumPy
• NumPy is the primary tool for scientific computing in Python.
• It combines the flexibility and simplicity of Python with the
speed of languages like C and Fortran.
• If you work with image data, make sure to check out the
Pillow package. It is a fork of PIL (Python Image Library) that
developed into an easy-to-use and efficient tool for image
manipulation in Python.