[BPLCK105B/205B]: Introduction to Python Programming
Python Programs
MODULE 1
1. Develop a Python program to calculate the area of rectangle
and triangle. Print the result.
Sol:
O/p:
2. Write a Python program to check whether the number is even
or odd.
Ans:
1|Page
[BPLCK105B/205B]: Introduction to Python Programming
O/p:
3. Develop a program to generate Fibonacci sequence of length
(N). Read N from the console.
Ans:
O/P:
4. Write a Python program to check whether the given number
is positive, negative or zero.
Ans:
2|Page
[BPLCK105B/205B]: Introduction to Python Programming
o/p:
MODULE 2
1. Develop a Python program to swap two numbers without
using intermediate variables. Prompt the user for input.
Ans:
3|Page
[BPLCK105B/205B]: Introduction to Python Programming
o/p:
MODULE 3
1. Develop a Python code to determine whether the given string
is a palindrome or not a palindrome.
Ans:
o/p:
4|Page
[BPLCK105B/205B]: Introduction to Python Programming
2. Develop a program to print the frequency of each digit with
suitable example
Ans:
o/p:
5|Page
[BPLCK105B/205B]: Introduction to Python Programming
MODULE 4
1. Develop a program with a function named DivExp which takes
two parameters a, b and returns a value C (C = a / b).
Write suitable assertion for a > 0 in function DivExp and raise
an exception for when b = 0.
Develop a suitable program which reads two values from the
console and calls a function DivExp.
Ans:
6|Page
[BPLCK105B/205B]: Introduction to Python Programming
o/p:
2. Develop a program to sort contents of a text file and write the
sorted content into a separate file.
Ans:
This program reads from [Link], sorts the contents, and writes them into
sorted_output.txt.
7|Page
[BPLCK105B/205B]: Introduction to Python Programming
o/p:
If [Link] contains:
Then sorted_output.txt will contain:
8|Page
[BPLCK105B/205B]: Introduction to Python Programming
MODULE 5
1. Write a program to explain pure function and modifier
function.
Ans:
• Pure Function: A function that does not modify any global or external state. It only
uses its input to return a value without side effects.
• Modifier Function: A function that modifies external or global variables, causing a
side effect.
o/p:
9|Page
[BPLCK105B/205B]: Introduction to Python Programming
2. Define a function which takes two objects representing
complex numbers and returns new complex number with a
addition of two complex numbers.
Define a suitable class ‘Complex’ to represent the complex
number.
Develop a program to read N (N >= 2) complex numbers and to
compute the addition of N complex numbers.
Ans:
10 | P a g e
[BPLCK105B/205B]: Introduction to Python Programming
o/p:
3. Define a class and object, construct the class called rectangle
and initialize it with height = 100, width = 200, starting point
as (x = 0, y = 0). Write a program to display the center point
co-ordinates of a rectangle.
Ans:
11 | P a g e
[BPLCK105B/205B]: Introduction to Python Programming
0/p:
12 | P a g e