0% found this document useful (0 votes)
3 views18 pages

Python Exp1

The document outlines the installation steps for Python and explains the differences between interactive and scripting modes in IDLE. It includes various experiments covering Python programming concepts such as variables, data types, arithmetic operations, and mathematical formulas. Each section provides theory, code examples, and learning outcomes to enhance understanding of Python programming.

Uploaded by

abhinavbhattuk
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)
3 views18 pages

Python Exp1

The document outlines the installation steps for Python and explains the differences between interactive and scripting modes in IDLE. It includes various experiments covering Python programming concepts such as variables, data types, arithmetic operations, and mathematical formulas. Each section provides theory, code examples, and learning outcomes to enhance understanding of Python programming.

Uploaded by

abhinavbhattuk
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

NAME - NIKHIL GOYAL

SAP ID - 590026332
BATCH - 26

PYTHON PROGRAMMING
EXPERIMENT 1
AIM- Install Python and write the steps of installation and
understand the difference between scripting and interactive modes
in IDLE.

THEORY- Steps to install Python:

[Link] a web browser.

[Link] to the official Python website:​


[Link]

[Link] on Downloads.

[Link] the latest version of Python for your operating


system (Windows / macOS / Linux).

[Link] the downloaded file.

[Link]: Tick the option “Add Python to PATH”.

[Link] on Install Now.

[Link] for the installation to complete.

[Link] installation, open IDLE (Python GUI) from the start


menu.

[Link] is now successfully installed.

Python IDLE

IDLE stands for Integrated Development and Learning


Environment.​
It is the default editor that comes with Python.
Difference between Interactive Mode and Scripting Mode in
IDLE
Interactive Mode Scripting Mode

Executes code line by line Executes entire program at once

Uses >>> prompt No >>> prompt

No need to save file File must be saved with .py


extension

Used for testing small Used for writing full programs


commands

Output shown immediately Output shown after running program

LEARNING OUTCOMES
After completing this experiment, the student will be able to:

1.​Understand the basics of Python programming language.


2.​Declare and use variables effectively.
3.​Identify and use different data types in Python.
4.​Perform arithmetic operations using operators.
5.​Write programs using mathematical formulas.
6.​Accept input from the user and display output.
7.​Apply logical thinking to solve real-world problems.
8.​Understand bitwise and shift operations.
9.​Use membership operators in sequences.
10.​ Develop problem-solving and programming [Link]
confidence in writing basic Python programs.
11.​ Understand the foundation required for advanced Python
concepts.

2. Variable and Data Type


Theory:

A variable is used to store data in memory. Python supports


different data types such as integer, float, string and boolean. The
type() function is used to identify the data type of a variable.

PYTHON CODE:

OUTPUT:

Learning Outcomes:

●​ Understand variables in Python


●​ Learn different data types
●​ Identify data types using type()
3. String Variable

Theory:

A string is a sequence of characters enclosed within


single or double quotes. Strings are used to store text
data in Python.

PYTHON CODE:

OUTPUT:

Learning Outcomes:

●​ Understand string data type


●​ Learn how to declare and print strings
4. Printing Different Data Types

Theory:

Python supports multiple data types such as integer,


float, string and boolean. The print() function is used
to display values on the output screen.

PYTHON CODE:

CODE:

Learning Outcomes:

●​ Identify different data types


●​ Use print function effectively
5. Arithmetic Operations

Theory:

Arithmetic operators are used to perform mathematical


calculations such as addition, subtraction,
multiplication and division.

PYTHON CODE:

OUTPUT:

Learning Outcomes:

●​ Understand arithmetic operators


●​ Perform basic mathematical operations
6. Pythagoras Theorem

Theory:

The Pythagoras theorem is used to find the hypotenuse of


a right-angled triangle using the formula​
c = √(a² + b²)
PYTHON CODE:

OUTPUT:

Learning Outcomes:

●​ Apply mathematical formulas in Python


●​ Compute hypotenuse of a triangle
7. Simple Interest
Theory:

Simple interest is calculated using the formula:​


SI = (P × R × T) / 100​
where P is principal, R is rate, and T is time.

PYTHON CODE:

OUTPUT:

Learning Outcomes:

●​ Understand financial calculations


●​ Implement formulas using Python
8. Area of Triangle
Theory:

When three sides of a triangle are known, Heron’s formula is used to


calculate the area.

PYTHON CODE:

OUTPUT:

Learning Outcomes:

●​ Learn Heron’s formula


●​ Calculate area of triangle using Python
9. Conversion of Seconds
Theory:

Time conversion can be done using division and modulus operators to


convert seconds into hours, minutes and remaining seconds.

PYTHON CODE:

OUTPUT:

Learning Outcomes:

●​ Understand integer division and modulus


●​ Perform time conversions

10. Swapping Two Numbers


Theory:

Python allows swapping of two numbers without using a third variable


through multiple assignment.

PYTHON CODE:

OUTPUT:

Learning Outcomes:

●​ Understand swapping logic


●​ Learn Python’s multiple assignment feature
11. Sum of First n Natural Numbers
Theory:

The sum of first n natural numbers is calculated using the formula:​


Sum = n(n + 1)/2

PYTHON CODE:

OUTPUT:

Learning Outcomes:

●​ Understand mathematical series


●​ Compute sum us
112. Bitwise Operators
Theory:

Bitwise operators perform operations on binary numbers. Operators


include AND (&), OR (|) and XOR (^).

PYTHON CODE:

OUTPUT:

Learning Outcomes:

●​ Understand binary operations


●​ Learn working of bitwise operators
13. Shift Operators
Theory:

Shift operators move bits left or right.​


Left shift (<<) multiplies the number, while right shift (>>) divides the
number.

PYHTON CODE:

OUTPUT:

Learning Outcomes:

●​ Understand bit shifting


●​ Apply left and right shift operators
14. Membership Operator
Theory:

The membership operator in checks whether a value is present in a


sequence such as list or tuple.

PYTHON CODE:

OUTPUT:

Learning Outcomes:

●​ Understand membership testing


●​ Use in operator with sequences

You might also like