0% found this document useful (0 votes)
2 views20 pages

Dhruv Python Lab File

The document is a lab file outlining various Python programming topics and exercises, including the introduction to Python, Jupyter Notebook, and hands-on programming tasks. It covers installation and setup of Anaconda, usage of Jupyter Notebook, and practical exercises on data types, control structures, and string operations. The lab file serves as a guide for students to learn and practice Python programming effectively.

Uploaded by

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

Dhruv Python Lab File

The document is a lab file outlining various Python programming topics and exercises, including the introduction to Python, Jupyter Notebook, and hands-on programming tasks. It covers installation and setup of Anaconda, usage of Jupyter Notebook, and practical exercises on data types, control structures, and string operations. The lab file serves as a guide for students to learn and practice Python programming effectively.

Uploaded by

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

LAB FILE

Name : ______________
Roll Number : ______________
Subject : ______________
Course and Section : ______________
Semester and Year : ______________
Submitted to : ______________
Index

S. No. Lab Topics Remarks

Understanding Jupyter IDE for


1 creating and executing a Python
program

Programming constructs in
2
python -hands-on practice

Programming constructs in
3
python -hands-on practice

4 Strings - hands-on practice

5 Basic String Operations


Lab: 1
1. Introducing the Python language, Understanding the Python shell.

Introducing Python:

Python is a high-level, interpreted programming language known for its simplicity and
readability. It was created by Guido van Rossum and first released in 1991. Python
supports multiple programming paradigms, including procedural, object-oriented, and
functional programming styles, making it versatile and suitable for various applications.

Understanding the Python Shell:

The Python shell, also known as the Python interactive interpreter, provides an
interactive environment for executing Python code line by line. It allows users to quickly
test code snippets, explore language features, and debug programs interactively.

To access the Python shell, you typically open your command-line interface (such as
Terminal on macOS or Command Prompt on Windows) and type python or python3,
depending on your system configuration and installed Python versions. This launches the
Python interpreter, and you'll see a prompt (>>>) where you can start typing Python
code.

2. Development environment setup, Configuring – Installation of Anaconda


IDE.

Setting up Anaconda, a popular Python distribution that includes a wide range of data
science and machine learning tools, is straightforward. Here's a step-by-step guide to
installing Anaconda:

Download Anaconda:

Visit the Anaconda website: Anaconda Distribution


Choose the appropriate version for your operating system (Windows, macOS, Linux).
Select the Python version (Python 3.x recommended).
Click on the download button and save the installer to your computer.
Install Anaconda:

Once the installer is downloaded, double-click it to start the installation process.


Follow the instructions in the installation wizard.
Choose whether to install Anaconda for just your user or for all users.
Select the installation location. The default location is usually fine.
After installation, you may be prompted to add Anaconda to your system PATH variable.
It's recommended to choose this option as it allows you to run Anaconda commands
from the command line.
Verify Installation:

Open a terminal (Command Prompt on Windows or Terminal on macOS/Linux).


Type conda --version and press Enter. You should see the version of Conda (the package
manager included with Anaconda) printed to the console.
Type python --version to confirm that Python is installed. This should display the version
of Python that comes with Anaconda.
Update Anaconda (Optional but recommended):

It's a good idea to update Anaconda after installation to ensure you have the latest
packages and bug fixes. You can do this by running the following command in your
terminal:
sql
Copy code
conda update anaconda
Install Anaconda Navigator (Optional but recommended):

Anaconda Navigator is a graphical user interface (GUI) for managing packages,


environments, and channels. To install it, run the following command:
Copy code
conda install anaconda-navigator
After installation, you can launch Anaconda Navigator from the Start menu (Windows) or
by typing anaconda-navigator in the terminal.
Additional Configuration (Optional):

You can create and manage Python environments using Conda. To create a new
environment, use the command conda create --name myenv where myenv is the name
of your environment.
You can activate your environment using conda activate myenv and deactivate it using
conda deactivate.
That's it! You've successfully installed Anaconda on your system. You can now start using
Anaconda's powerful tools and libraries for data science and machine learning.
3. Introduction to jupyter notebook.

Jupyter Notebook is an open-source web application that allows you to create and share
documents that contain live code, equations, visualizations, and narrative text. It's
widely used in data science, machine learning, scientific research, and education
because of its interactive and collaborative nature.

Here's a breakdown of its key features and components:

1. Interactive Environment: Jupyter Notebook provides an interactive computing


environment where you can write and execute code in various programming languages,
including Python, R, Julia, and more. Each notebook consists of cells where you can input
code or text.

2. Code Execution: You can execute code cells individually, which allows for rapid
prototyping, testing, and debugging. The results of code execution (output, plots, etc.)
are displayed directly below the code cell.

3. Markdown Support: In addition to code cells, Jupyter Notebook supports Markdown


cells, where you can write formatted text, equations using LaTeX, and include images,
links, and other multimedia content. This makes it suitable for creating rich, interactive
documents.

4. Visualization: Jupyter Notebook integrates seamlessly with libraries like Matplotlib,


Seaborn, Plotly, and others for data visualization. You can create interactive plots, charts,
and graphs directly within your notebooks.

5. Rich Outputs: Apart from textual output, Jupyter Notebook can display rich media
outputs, including HTML, images, videos, and interactive widgets. This feature enables
you to create dynamic and engaging presentations or reports.

6. Integration with External Tools: Jupyter Notebook supports integration with various
external tools and libraries, including version control systems like Git, data processing
libraries like Pandas, and machine learning frameworks like TensorFlow and PyTorch.

7. Shareability and Collaboration: You can share your Jupyter Notebooks with others by
exporting them to various formats like HTML, PDF, or slides. Additionally, platforms like
GitHub, JupyterHub, and Google Colab allow for collaborative editing and sharing of
notebooks.
8. Extensions and Customization: Jupyter Notebook offers a range of extensions and
customization options to enhance your workflow. You can install extensions for
additional functionalities, themes for visual customization, and keyboard shortcuts for
faster navigation.

Overall, Jupyter Notebook is a powerful tool for data analysis, exploration, visualization,
and communication.

4. Working with jupyter notebook.

Working with Jupyter Notebook can be a rewarding experience, especially for data
scientists, researchers, and educators. Here's a brief overview of how to get started:

Installation: If you haven't installed Jupyter Notebook yet, you can do so via pip
(Python's package manager). Simply run pip install notebook in your command line.

Launching Jupyter Notebook: After installation, you can start Jupyter Notebook by typing
jupyter notebook in your command line. This will launch a local server and open a new
tab or window in your default web browser.

Creating a New Notebook: Once Jupyter Notebook is open, you can create a new
notebook by clicking on the "New" button in the top right corner and selecting "Python
3" (or any other available kernels you may have installed).

Writing and Running Code: In a Jupyter Notebook, you'll see cells where you can write
and execute code. To run a cell, you can either click the "Run" button in the toolbar,
press Shift + Enter, or use other keyboard shortcuts like Ctrl + Enter (to run the current
cell without advancing) or Alt + Enter (to run the current cell and insert a new one
below).

Markdown Cells: Jupyter Notebook supports Markdown cells, which allow you to write
formatted text, add images, create lists, tables, etc. To create a Markdown cell, change
the cell type from "Code" to "Markdown" using the dropdown menu in the toolbar.

Saving and Exporting: Jupyter Notebooks are automatically saved periodically, but you
can also save manually by clicking on the floppy disk icon in the toolbar or by pressing
Ctrl + S. You can export your notebook to various formats such as HTML, PDF, or slides by
navigating to "File" -> "Download as" and selecting the desired format.
Other Features: Jupyter Notebook has many other features, such as the ability to install
and use different kernels (for languages other than Python), support for interactive
widgets, and integration with version control systems like Git.

Extensions: You can enhance Jupyter Notebook's functionality by installing extensions.


Popular extensions include Table of Contents, Collapsible Headings, and Code Formatter.

Shutdown: Once you're done working with a notebook, it's a good practice to shut down
the notebook's kernel to free up system resources. You can do this by selecting "File" ->
"Close and Halt" for the specific notebook you're working on or by shutting down the
entire Jupyter Notebook server.

Jupyter Notebook's flexibility and interactivity make it a powerful tool for data analysis,
visualization, and prototyping code.

5. Writing a simple program.


Lab: 2

1. Basic data types:

2. Even or odd:
3. Leap Year

4. Vowel or Consonants

5. Smallest of two numbers


6. Factorial of a number

7. Star pattern.

8. Fibonacci Series
9. Prime or not

10. Simple calculator

Lab: 3
1) Swapping two numbers (Using third variable):

2) Swapping two numbers (without using third variable):

3) Sum of cubes:
4) If two variables are equal:

5) Smallest of three

6) Smallest of three (without using sort function)


7) Area of Circle

8) If even find square, otherwise find cube


Lab:4

1. WAP to demonstrate while loop with else statement.

2. Print 1st 5 even numbers (use break statement).


3. Print 1st 4 even numbers (use continue statement).

4. WAP to demonstrate Pass statements.

5. Write a Python program to calculate the length of a string.


6. Write a Python program to count the number of characters (character
frequency) in a string

7. Write a Python program to get a string made of the first 2 and the last 2 chars
from a given a string. If the string length is less than 2, return instead of the
empty string.
Lab: 5

1. Slicing Operations in Strings

2. Built-in Functions of Strings


3. Checking Palindrome

4. Capitalize First and Last Character of Each Word

5. Displaying Common Words


6. Counting Frequency of Each Vowel

7. Displaying Smallest Word

You might also like