[go: up one dir, main page]

0% found this document useful (0 votes)
9 views10 pages

LB 13

This document serves as a lab introduction to Python programming, covering its basic structure, syntax, and differences from other languages. It includes hands-on tasks for students to write simple Python programs, solve mathematical problems, and plot graphs using libraries like Matplotlib. Additionally, it provides an overview of various Python libraries such as NumPy, Tkinter, and datetime, highlighting their purposes and applications.

Uploaded by

hamzachlhr111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

LB 13

This document serves as a lab introduction to Python programming, covering its basic structure, syntax, and differences from other languages. It includes hands-on tasks for students to write simple Python programs, solve mathematical problems, and plot graphs using libraries like Matplotlib. Additionally, it provides an overview of various Python libraries such as NumPy, Tkinter, and datetime, highlighting their purposes and applications.

Uploaded by

hamzachlhr111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Lab # 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.

EXAMPLE 1: get hello world in output.


Program:

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:

2. Write a python program to find the area of triangle?


PROGRAM:

OUTPUT:

3.Write a python program to find Area of circle?


PROGRAM:
OUTPUT:

4. Write a python program to find modulus of any number?


PROGRAM:

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.

The (plt) alias makes it easier to refer to (matplotlib.pyplot) throughout the


code.
3. Plotting Basic Graphs
Now, let’s go through some basic types of graphs you can plot with matplotlib.
A. Line Graph
A line graph is typically used to represent data points that are connected by a
line. It is helpful in showing trends over time.
Example: Plotting a Line Graph
PROGRAM:
OUTPUT:

2. Explain python libraries one by one.


ANSWER:

➢ NumPy (Numerical Python)


Purpose: Fast mathematical operations on arrays and matrices.
Key Features:
• Supports large multi-dimensional arrays.
• Provides mathematical functions like mean, standard deviation, dot
product, etc.
Example:

Output:

Used in: Data science, machine learning, scientific computing.

➢ 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:

Used in: Desktop apps, tools.

➢ 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.

➢ datetime – Date and Time Handling


Purpose: Work with dates, times, durations.
Example:

OUTPUT:

Excellent for time-based programs (like reminders, logs, etc.)

➢ random – Random Number Generation


Purpose: Generate random numbers, shuffle lists, pick random items.
Example:

OUTPUT:

Built-in and very useful for games, simulations, or testing.


➢ os – Operating System Interaction
Purpose: Work with files, folders, and environment.
Example:

OUTPUT:

Great for file management scripts.


➢ math – Mathematical Functions
Purpose: Provides basic math functions like square root, power, trigonometry,
constants (π, e).
Example:

OUTPUT:

No installation needed — it’s built-in.


<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

You might also like