LB 13
LB 13
Introduction to Python
Objectives:
• To introduce the basic structure and syntax of the Python programming language.
• To understand the differences between Python and other programming languages.
• To develop and execute simple Python programs using standard input/output.
• To apply Python for solving basic mathematical problems such as calculating area,
modulus, and ASCII values.
• To introduce the concept of plotting graphs using Python and explore commonly used
Python libraries.
• To build confidence in writing and testing Python code in a text editor or integrated
development environment (IDE).
Introduction:
Python is a powerful, easy-to-learn programming language that is widely used in today’s software and
hardware development industries. Developed by Guido van Rossum in 1991, Python has gained popularity
due to its simple syntax, readability, and flexibility. It supports various programming approaches including
procedural, object-oriented, and functional programming.
This lab introduces students to the basics of Python programming. It includes hands-on experience with
writing Python code, understanding syntax, and solving basic computational problems. By working through
these tasks, students begin developing logical thinking skills and a foundation for writing effective Python
code.
Output:
EXAMPLE 2: To add two floating numbers.
PROGRAM:
OUTPUT:
LAB TASK
1. Write a python Program to print ASCII Value of a
character?
PROGRAM:
OUTPUT:
OUTPUT:
OUTPUT:
LAB SESSION
1.How to plot a graph in python give detail with
example.
Plotting a Graph in Python with Matplotlib
To plot graphs in Python, the most commonly used library is Matplotlib. It
provides functions to create a wide variety of plots such as line graphs, bar
charts, scatter plots, histograms, and more. Below is a step-by-step guide to
installing, importing, and plotting graphs using matplotlib.
1. Installation of Matplotlib
Before we can use matplotlib, we need to install it. If you don’t have it installed
yet, you can use pip to install it.
Command:
This will download and install the necessary files for matplotlib.
2. Importing Matplotlib
Once you have installed matplotlib, you need to import it into your Python
code. The most common alias used for matplotlib is plt.
Output:
➢ Matplotlib
Purpose: Creating static, animated, and interactive plots.
Key Features:
• Line charts, bar charts, histograms, scatter plots, etc.
• Works well with NumPy and Pandas.
Example:
Output:
Used in: Data visualization.
➢ Tkinter
Purpose: Creating GUI (graphical user interface) applications.
Key Features:
• Buttons, labels, input boxes.
• Windows and dialogs.
Example:
OUTPUT:
➢ Math:-
Purpose: Basic math operations (part of Python standard library).
Key Features:
• Square roots, trigonometry, logarithms, constants (like pi).
Example:
OUTPUT:
Used in: General-purpose math tasks.
OUTPUT:
OUTPUT:
OUTPUT:
OUTPUT: