python report-1
python report-1
Of
PYTHON
Submitted by:-
Shambhavi Kumari
1. Introduction 3
2. Arithmetic Problems 4
3. Range 11
4. Perfect number 14
5. Conclusion 15
But, before understanding of program we have to understand what is
python and where does it helps us :
Printing "Hello, World!" is a beginner-friendly way to learn the basic syntax of a programming
language and ensure the development environment is set up correctly. It’s a simple, confidence-
building step that helps verify everything is working before moving on to more complex coding tasks.
Arithmetic Operations:
1. Addition (+)
2. Subtraction (-)
3. Multiplication (*)
4. Division (/)
5. Floor Division (//)
6. Modulus (%)
7. Exponentiation (**)
INPUT:
OUTPUT:
2. Subtraction (-):
INPUT:
T
OUTPUT:
3. Multiplication (*):
INPUT:
OUTPUT:
4. Division (/):
The division operator divides one number by another and returns the result as a float:
INPUT:
OUTPUT:
5. Floor Division (//):
The floor division operator divides one number by another and returns the largest
integer value less than or equal to the division result:
INPUT:
OUTPUT:
6. Modulus (%):
INPUT:
OUTPUT:
7. Exponentiation (**):
The exponentiation operator is used to raise a number to the power of another number:
INPUT:
OUTPUT:
\
A list in Python is a collection of items (or elements) that can store multiple values in
a single variable. Lists are one of Python's most flexible and commonly used data
structures because they can store items of different data types, and their size can
change dynamically. Lists are mutable, meaning their contents can be modified after
creation (e.g., items can be added or removed).
CREATING LISTS:
Empty list: You can create an empty list using square brackets []
Output:
Entering Elements into Lists:
Output:
INPUT:
OUTPUT:
Output:
Lists in Python are versatile and provide various methods for entering, deleting, and
modifying elements. They are an essential part of Python's data structures and can be
used for dynamic and flexible data storage and manipulation.
RANGE():
Syntax of range():
There are three ways to use range() based on the number of arguments passed:
1. Range(stop) :
Input:
Output:
Output:
Range (start, stop, step ) :
Input:
Output:
The range() function in Python is a versatile and powerful way to generate sequences
of numbers, commonly used in loops for iteration. It provides a convenient and
memory-efficient method to handle numerical ranges.
PERFECT NUMBER:
A perfect number is a positive integer that equals the sum of its proper divisors,
excluding itself. For instance, 6 is perfect because its divisors (1, 2, and 3) sum to 6.
Similarly, 28 is perfect because its divisors (1, 2, 4, 7, and 14) sum to 28. These
numbers are significant in number theory for their unique properties.
Example:
6 is a perfect number:
o Proper divisors of 6: 1, 2, 3
o Sum of divisors: 1 + 2 + 3 = 6
28 is another perfect number:
o Proper divisors of 28: 1, 2, 4, 7, 14
o Sum of divisors: 1 + 2 + 4 + 7 + 14 = 28
Perfect numbers are rare, and the first few perfect numbers are 6, 28, 496, and 8128.
Program for Perfect numbers:
Input:
Output:
Input:
Output:
FACTORIAL NUMBER
A factorial number represents the product of all positive integers less than or equal to
that
number. It's denoted by the symbol "!".
Formula:
• n! = n × (n-1) × (n-2) × ... × 2 × 1
Examples:
• 0! = 1 (by definition)
• 1! = 1
• 2! = 2 × 1 = 2
• 3! = 3 × 2 × 1 = 6
• 4! = 4 × 3 × 2 × 1 = 24
Print The Length of a Given Sequence:
INPUT:
OUTPUT:
Fibonacci Series:
The Fibonacci series is a sequence of numbers where each number is the sum of the
two
preceding ones. It starts with 0 and 1, and the sequence continues as follows:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
Formula:
F(n) = F(n-1) + F(n-2)
Where:
• F(n) is the nth Fibonacci number.
• F(n-1) is the (n-1)th Fibonacci number.
• F(n-2) is the (n-2)th Fibonacci number.
• Nature:
22o The arrangement of leaves on a stem
o The branching of trees
o The spiral patterns in pinecones and sunflowers
o The growth patterns of some plants
• Mathematics:
o Golden ratio
o Fractals
o Algorithms and data structures
• Computer Science:
o Searching and sorting algorithms
o Data compression
o Game theory
INPUT:
OUTPUT:
Armstrong Number:
An Armstrong number is a number that is equal to the sum of its own digits, each
raised to the power of the number of digits.
Example:
Consider the number 153.
• It has 3 digits.
• 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
Since the sum of the cubes of its digits equals the number itself, 153 is an Armstrong
number.
Other examples of Armstrong numbers:
23• 0
•1
• 370
• 371
• 407
INPUT:
OUTPUT:
Declaration of Variables to store the count values:
• Size: 0
• Top element: None (since there's no element to be on top)
• Operations:
o Push: Adds an element to the top of
the stack.
o Pop: Removes and returns the top
element from the stack. This
operation is not possible on an
empty stack.
o Peek: Returns the top element
without removing it. This operation
is not possible on an empty stack.
o IsEmpty: Returns True if the stack
is empty.
INPUT:
OUTPUT:
Excel File Handling:
Specify the column name and get its index:
CONCLUSION
In conclusion, Python has proven to be a powerful, adaptable, and user-
friendly programming language. It has shown to be a fantastic choice for
developers working in a range of fields, including web development, data
science, machine learning, and automation, because of its simplicity of
use and large library ecosystem. Dynamic typing makes Python easy to
use for beginners and robust enough for experts to tackle complex tasks;
its simple syntax encourages readability and streamlines functionality.