Date:18/03/2026
ASSIGNMENT-1
Problem Statement: Write a Python program to design a basic
calculator.
Source Code:
print("Basic Calculator")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
choice = input("Enter choice (1/2/3/4): ")
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
print("Result =", num1 + num2)
elif choice == '2':
print("Result =", num1 - num2)
elif choice == '3':
print("Result =", num1 * num2)
elif choice == '4':
if num2 != 0:
print("Result =", num1 / num2)
else:
print("Division by zero is not possible")
else:
print("Invalid Input")
Output:
Basic Calculator
1. Addition
2. Subtraction
3. Multiplication
4. Division
Enter choice (1/2/3/4): 1
Enter first number: 10
Enter second number: 5
Result = 15.0
Discussion: The program is a simple basic calculator written in Python. It
performs four arithmetic operations: addition, subtraction, multiplication,
and division. First, the program displays a menu of operations and takes
the user’s choice as input. Then it asks the user to enter two numbers.
Using if, elif, and else statements, the program checks the selected option
and performs the corresponding calculation. For division, it also checks
whether the second number is zero to avoid division by zero errors.
Finally, the result is displayed on the screen.
1
Date:18/03/2026
ASSIGNMENT-2
Problem Statement: Write a Python program to find the largest among
three numbers.
Source Code:
a = int(input ("Enter First No.:"))
b = int(input ("Enter Second No.:"))
c = int(input ("Enter Third No.:"))
if(a>b and a>c):
print("a is Biggest")
elif(b>a and b>c):
print("b is Biggest")
else:
print("c is Biggest")
Output:
Enter First No.:54
Enter Second No.:98
Enter Third No.:65
B is Biggest
Discussion: This Python program finds the biggest number among three
numbers. It takes three inputs from the user and stores them in a, b, and
c. Using if, elif, and else statements, the program compares the numbers
and prints the biggest one.
2
Date:18/03/2026
ASSIGNMENT-3
Problem Statement:Write a Python program to take 3 angles of a
triangle and check whether the triangle is possible or not. If possible, then
check whether it is an acute angle triangle, right angle triangle, or obtuse
angle triangle.
Source Code
a = int(input("Enter First No.: "))
b = int(input("Enter Second No.: "))
c = int(input("Enter Third No.: "))
if(a + b + c == 180):
print("Triangle is Possible.")
if(a == 90 or b == 90 or c == 90):
print("It is a Right Angle Triangle.")
elif(a > 90 or b > 90 or c > 90):
print("It is an Obtuse Angle Triangle.")
else:
print("It is an Acute Angle Triangle.")
else:
print("Triangle is not Possible.")
Output
Enter First No.: 60
Enter Second No.: 60
Enter Third No.: 60
Triangle is Possible.
It is an Acute Angle Triangle.
Discussion: This Python program takes three angle values as input. If
the sum of all three angles is 180, the triangle is possible; otherwise, it is
not possible. Then, the program checks the type of triangle. If any angle is
90, it is a right-angle triangle. If any angle is greater than 90, it is an
obtuse-angle triangle. Otherwise, it is an acute-angle triangle.
Date:18/03/2026
3
ASSIGNMENT-4
Problem Statement: Write a Python program to take 3 angles of a
triangle and check it possible or not., If possible then check whether
equilateral triangle or isosceles triangle or scalene triangle.
Source Code:
a = float(input ("Enter First Side:"))
b = float(input ("Enter Second Side:"))
c = float(input ("Enter Third Side:"))
if((a + b >= c) and (a + c >= b) and (b + c >= a)):
print("Triangle is Possible.")
else:
print("Triangle is Not Possible.")
if(a==b==c):
print("It is an Equilateral Triangle.")
elif(a == b or b == c or a == c):
print("It is an Isosceles Triangle.")
else:
print("It is an Scalene Triangle.")
Output:
Enter First Side:7
Enter Second Side:10
Enter Third Side:5
Triangle is Possible.
It is an Scalene Triangle.
Discussion: This Python program checks whether a triangle is possible
using the given three sides. It first takes the side lengths as input from the
user. Using the triangle inequality rule, it checks if the sum of any two
sides is greater than or equal to the third side. If true, the triangle is
possible. Then, the program identifies the type of triangle. If all sides are
equal, it is an equilateral triangle. If any two sides are equal, it is an
isosceles triangle. Otherwise, it is a scalene triangle.
Date:18/03/2026
4
ASSIGNMENT-5
Problem Statement: Write a Python program to check a number is
Armstrong or not.
Source Code:
num = int(input("Enter a No.:"))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
Output:
Enter a No.:407
407 is an Armstrong number
Discussion: This Python program checks whether a number is an
Armstrong number or not. First, the program takes a number as input
from the user. Using a while loop, it separates each digit of the number,
finds the cube of the digit, and adds them together. Finally, it compares
the sum with the original number. If both are equal, the number is an
Armstrong number; otherwise, it is not an Armstrong number.
Date:18/03/2026
ASSIGNMENT-6
Problem Statement: Write a Python program to check whether a number
is palindrome or not.
5
Source Code:
num = int(input("Enter a Number: "))
temp = num
reverse = 0
while temp > 0:
digit = temp % 10
reverse = reverse * 10 + digit
temp //= 10
if num == reverse:
print(num, "is a Palindrome Number")
else:
print(num, "is not a Palindrome Number")
Output:
Enter a Number: 121
121 is a Palindrome Number
Discussion: This Python program checks whether a number is a
palindrome or not. It reverses the digits of the given number using a while
loop and compares the reversed number with the original number. If both
are equal, the number is a palindrome number; otherwise, it is not a
palindrome number.
Date:18/03/2026
ASSIGNMENT-7
Problem Statement: Write a Python program to print Fibonacci series.
6
Source Code:
n = int(input("Enter the number of terms: "))
a=0
b=1
print("Fibonacci Series:")
for i in range(n):
print(a, end=" ")
c=a+b
a=b
b=c
Output:
Enter the number of terms: 7
Fibonacci Series:
0112358
Discussion: This Python program prints the Fibonacci series up
to a given number of terms. It starts with 0 and 1, then each
next number is obtained by adding the previous two numbers.
A for loop is used to generate and display the series.
Date:23/03/2026
ASSIGNMENT-8
Problem Statement: Write a Python program to display Pascal’s triangle.
Source Code:
n = int(input("Enter number of rows: "))
7
for i in range(n):
number = 1
# Print spaces
for j in range(n - i - 1):
print(" ", end=" ")
# Print numbers
for j in range(i + 1):
print(number, end=" ")
number = number * (i - j) // (j + 1)
print()
Output:
Enter number of rows: 5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Discussion: This program displays Pascal’s Triangle using nested loops.
The outer loop controls the number of rows, while the first inner loop
prints spaces for proper triangle formatting. The second inner loop prints
the numbers in each row. The variable number starts from 1 and the next
values are calculated using the Pascal’s Triangle formula number =
number * (i – j) // (j + 1) . After printing each row, print() moves the cursor
to the next line.
Date:23/03/2026
ASSIGNMENT-9
Problem Statement: Write a Python program to display the following
pattern using nested loops.
11
22 21
333 321
4444 4321
8
55555 54321
Source Code:
for i in range(1, 6):
# Left side pattern
for j in range(i):
print(i, end="")
print(" ", end="")
# Right side pattern
for j in range(i, 0, -1):
print(j, end="")
print()
Output:
11
22 21
333 321
4444 4321
55555 54321
Discussion: This Python program prints a number pattern using nested
for loops. The outer loop controls the number of rows from 1 to [Link] each
row, the first inner loop prints the same number repeatedly according to
the row number. For example, in the third row, 333 is printed. After
printing a space, the second inner loop prints numbers in decreasing order
from the current row number down to 1.
Thus, the program creates a combined pattern where the left side
contains repeated numbers and the right side contains descending
numbers.
Date:23/03/2026
ASSIGNMENT-10
Problem Statement: Write a program that uses a while loop to add up
all the even numbers between 100 and 200
Source Code:
9
start = int(input("Enter starting number: "))
end = int(input("Enter ending number: "))
sum = 0
while start <= end:
if start % 2 == 0:
sum += start
start += 1
print("Sum of even numbers =", sum)
Output:
Enter starting number: 100
Enter ending number: 200
Sum of even numbers = 7650
Discussion: This program uses a while loop to calculate the sum of all
even numbers between two user-given numbers. The starting and ending
values are taken as input from the user. The variable sum is initialized to
0. Inside the loop, the condition start % 2 == 0 checks whether the
current number is even. If the number is even, it is added to sum. After
each iteration, the value of start is increased by 1 until it becomes greater
than the ending number. Finally, the total sum of all even numbers is
displayed.
Date:23/03/2026
ASSIGNMENT-11
Problem Statement: Write a program print the sum of the following
series
a. 1 + ½ + 1/3 +. …. + 1/n
b. 1/1 + 22/2 + 33/3 + ……. + nn/n
10
Source Code:
n = int(input("Enter value of n: "))
sum1 = 0
sum2 = 0
for i in range(1, n + 1):
sum1 = sum1 + (1 / i) # Sum of series: 1 + ½ + 1/3 + ... + 1/n
sum2 = sum2 + (i ** i) / i # Sum of series: 1^1/1 + 2^2/2 + 3^3/3
+ ... + n^n/n
print("Sum of series 1 =", sum1)
print("Sum of series 2 =", sum2)
Output:
Enter value of n: 3
Sum of series 1 = 1.8333333333333333
Sum of series 2 = 12.0
Discussion: This program calculates the sums of two different series
together using a single for loop. The variable sum1 stores the sum of the
series 1 + 1/2 + 1/3 + ... + 1/n, while sum2 stores the sum of the series
(1^1)/1 + (2^2)/2 + ... + (n^n)/n. In each iteration, both series terms are
calculated and added to their respective sums. After the loop ends, the
final sums of both series are displayed.
Date:23/03/2026
ASSIGNMENT-12
Problem Statement: Write a Python program to find the depreciation
value of an asset (property) by reading the purchase value of the asset
(amt), year of the service (year) and the value of depreciation.
11
Source Code:
amt = float(input("Enter purchase value of asset: "))
year = int(input("Enter years of service: "))
dep = float(input("Enter depreciation percentage: "))
value = amt
for i in range(year):
value = value - (value * dep / 100)
print("Depreciated value of asset =", value)
Output:
Enter purchase value of asset: 50000
Enter years of service: 3
Enter depreciation percentage: 10
Depreciated value of asset = 36450.0
Discussion: This program calculates the depreciated value of an asset
after a certain number of years. The purchase value of the asset, years of
service, and depreciation percentage are taken as input from the user. The
variable value initially stores the original asset value. A for loop runs for
the given number of years, and in each iteration the depreciation amount
is calculated and subtracted from the current value. After completing all
years, the final depreciated value of the asset is displayed.
Date:25/04/2026
ASSIGNMENT-13
Problem Statement: Write a program that accepts a string from the user
and display the same string after removing vowels from it.
Source Code:
str1 = input("Enter a string: ")
12
vowels = "aeiouAEIOU"
result = ""
for ch in str1:
if ch not in vowels:
result = result + ch
print("String after removing vowels:", result)
Output:
Enter a string: Computer Science
String after removing vowels: Cmptr Scnc
Discussion: This Python program accepts a string from the user and
removes all vowels from it. First, the user enters a string. Then the
program checks each character one by one using a loop. If the character
is not a vowel (a, e, i, o, u in both uppercase and lowercase), it is added to
a new string. Finally, the modified string without vowels is displayed as
output.
Date:25/04/2026
ASSIGNMENT-14
Problem Statement: Write a function to insert a string in the middle of
the string.
Source Code:
def insmid(str1, str2):
middle = len(str1) // 2
13
newstr = str1[:middle] + str2 + str1[middle:]
return newstr
text1 = input("Enter first string: ")
text2 = input("Enter second string: ")
print("New string:", insmid(text1, text2))
Output:
Enter first string: HelloWorld
Enter second string: Python
New string: HelloPythonWorld
Discussion: This Python program defines a function named insmid() to
insert one string into the middle of another string. First, the middle
position of the first string is calculated using the length of the string
divided by 2. Then the second string is inserted at that position using
string slicing. Finally, the new combined string is displayed.
Date:25/04/2026
ASSIGNMENT-15
Problem Statement: Write a program to sort a string lexicographically.
Source Code:
str1 = input("Enter a string: ")
ch = ""
for i in range(len(str1)):
14
for j in range(i + 1, len(str1)):
if str1[i] > str1[j]:
ch = str1[i]
str1 = str1[:i] + str1[j] + str1[i+1:]
str1 = str1[:j] + ch + str1[j+1:]
print("Sorted string:", str1)
Output:
Enter a string: python
Sorted string: hnopty
Discussion: This Python program sorts the characters of a string in
lexicographical order. The program compares each character with the
remaining characters using nested loops. If a character is greater than
another character, their positions are swapped using string slicing. After
all comparisons, the string becomes sorted in alphabetical order and is
displayed as output
Date:25/04/2026
ASSIGNMENT-16
Problem Statement: Write a program to replace a string with another
string without using built-in methods.
Source Code:
str1 = input("Enter the main string: ")
old = input("Enter the string to replace: ")
new = input("Enter the new string: ")
15
result = ""
i=0
while i < len(str1):
match = True
for j in range(len(old)):
if i + j >= len(str1) or str1[i + j] != old[j]:
match = False
break
if match:
result = result + new
i = i + len(old)
else:
result = result + str1[i]
i=i+1
print("New string:", result)
Output:
Enter the main string: I like mango
Enter the string to replace: mango
Enter the new string: apple
New string: I like apple
Discussion: This Python program replaces one string with another
string without using any built-in replace method. First, the user enters the
main string, the old string, and the new string. The program checks each
position of the main string using a loop. If the old string matches the
characters at that position, the new string is added to the result.
Otherwise, the original character is added. Finally, the modified string is
displayed.
Date:25/04/2026
ASSIGNMENT-17
Problem Statement: Write a program to concatenate two strings into
another string without using the + operator
Source Code:
str1 = input("Enter first string: ")
str2 = input("Enter second string: ")
result = ""
for ch in str1:
16
result += ch
for ch in str2:
result += ch
print("Concatenated string:", result)
Output:
Enter first string: Python
Enter second string: Programming
Concatenated string: PythonProgramming
Discussion: This Python program concatenates two strings without
directly using the + operator between the strings. First, the user enters
two strings. An empty string variable is created to store the final result.
Then two loops are used to add each character of the first and second
strings one by one into the result string. Finally, the concatenated string is
displayed.
Date:25/04/2026
ASSIGNMENT-18
Problem Statement: Write a program to strip a set of characters from a
string.
Source Code:
str1 = input("Enter a string: ")
remove = input("Enter characters to remove: ")
result = ""
for ch in str1:
found = False
17
for r in remove:
if ch == r:
found = True
break
if found == False:
result = result + ch
print("String after stripping characters:", result)
Output:
Enter a string: computer science
Enter characters to remove: ce
String after stripping characters: omputr sni
Discussion: This Python program removes a set of characters from a
string without using built-in strip methods. First, the user enters a string
and the characters to be removed. The program checks each character of
the main string using a loop. If the character matches any character from
the remove string, it is skipped. Otherwise, it is added to the result string.
Date:25/04/2026
ASSIGNMENT-19
Problem Statement: Write a program to extract the first n characters of
a string.
Source Code:
str1 = input("Enter a string: ")
n = int(input("Enter the number of characters: "))
result = ""
for i in range(n):
18
if i < len(str1):
result = result + str1[i]
print("First", n, "characters:", result)
Output:
Enter a string: Computer
Enter the number of characters: 4
First 4 characters: Comp
Discussion: This Python program extracts the first n characters from a
string. First, the user enters a string and the value of n. A loop runs from 0
to n-1 and adds each character to a new string one by one. The condition i
< len(str1) ensures that the program does not go beyond the string
length. Finally, the extracted characters are displayed as output.
19