NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 1:
Write a python program to find the grade of the students based on marks scored in 5 subjects.
Objective:
To write a Python program that accepts marks of five subjects, calculates the total and average,
and determines the student’s grade based on predefined grading criteria using conditional
statements.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
marks = []
for i in range(5):
mark = float(input(f"Enter marks of subject {i+1}: "))
[Link](mark)
total = sum(marks)
avg = total / 5
if avg >= 90:
grade = 'A+'
elif avg >= 80:
grade = 'A'
elif avg >= 70:
grade = 'B'
elif avg >= 60:
grade = 'C'
elif avg >= 50:
grade = 'D'
else:
grade = 'F'
print(f"Grade of the student is: {grade}")
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 2:
Write a python program to calculate area of triangle by heron’s formulae.
Objective:
To write a Python program that calculates the area of a triangle using Heron's formula given
the lengths of three sides.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
import math
a = float(input('Enter side a: '))
b = float(input('Enter side b: '))
c = float(input('Enter side c: '))
s = (a + b + c) / 2
area = [Link](s * (s - a) * (s - b) * (s - c))
print(f'Area of the triangle is: {area}')
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 3:
Write a python program to check whether a number is palindrome or not.
Objective:
To check whether a given number is a palindrome by reversing it using arithmetic operations
and comparing it with the original number, while practicing loops and conditional statements.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
num = input("Enter a number: ")
if num == num[::-1]:
print("The number is a palindrome")
else:
print("The number is not a palindrome")
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 4:
Write a python program to print all the prime numbers below a number taken as input from the user
( Using while loop)
Objective:
To write a Python program that lists all prime numbers less than a user input using a while
loop.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
n = int(input("Enter a number: "))
i=2
while i < n:
is_prime = True
for j in range(2, i):
if i % j == 0:
is_prime = False
break
if is_prime:
print(i, end=" ")
i += 1
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 5:
Write a python program to find the sum of the given series up to n numbers taken as input from the
user.
1+1/!2+1/!3+……..1/!n
1+22+33+………nn
Objective:
To write Python programs calculating the sum of two different series up to n terms entered by
the user.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
(Series 1)
import math
n = int(input("Enter n: "))
sum1 = 1
for i in range(2, n+1):
sum1 += 1 / [Link](i)
print(f"Sum of series 1 is: {sum1}")
Output:
Python code:
(Series 2)
n = int(input("Enter n: "))
sum2 = 0
for i in range(1, n+1):
sum2 += i**i
print(f"Sum of series 2 is: {sum2}")
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 6:
Write a python program to create a list of n numbers taken input from the user. Calculate the mean,
median and mode for the created list.
Objective:
To write a Python program that takes n numbers from the user and calculates mean, median,
and mode.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
from statistics import mean, median, mode
n = int(input("Enter number of elements: "))
numbers = []
for _ in range(n):
num = float(input())
[Link](num)
print("Mean:", mean(numbers))
print("Median:", median(numbers))
print("Mode:", mode(numbers))
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 7:
Write a python program to take a string as input and count the vowels, digits and consonants. Store
and display the result in dictionary format.
Objective:
To write a Python program that counts vowels, digits, and consonants in a string and stores the
result in a dictionary.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
s = input("Enter a string: ")
vowels = 'aeiouAEIOU'
count = {'vowels':0, 'digits':0, 'consonants':0}
for char in s:
if char in vowels:
count['vowels'] += 1
elif [Link]():
count['digits'] += 1
elif [Link]():
count['consonants'] += 1
print(count)
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 8:
Write a program that extracts and prints the characters from an input string that are present at prime
indices (0-based index) using slicing.
Objective:
To write a Python program that prints characters from a string located at prime indices.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
def is_prime(num):
if num < 2:
return False
for i in range(2, int(num**0.5)+1):
if num % i == 0:
return False
return True
s = input("Enter a string: ")
result = ''
for i in range(len(s)):
if is_prime(i):
result += s[i]
print("Characters at prime indices:", result)
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 9:
Write a program to create two sets taking input from the user and perform the following operations on
them using operators and set methods
Union
Intersection
Symmetric difference
Difference
Sets are disjoint or not
Objective:
To demonstrate set operations and membership with user inputs.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
set1 = set(map(int, input("Enter elements of set1 separated by space: ").split()))
set2 = set(map(int, input("Enter elements of set2 separated by space: ").split()))
print("Union:", set1 | set2)
print("Intersection:", set1 & set2)
print("Symmetric difference:", set1 ^ set2)
print("Difference (set1 - set2):", set1 - set2)
print("Difference (set2 - set1):", set2 - set1)
print("Are sets disjoint?", [Link](set2))
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 10:
Write a program to implement a simple calculator . The program should take three inputs from the
user: num1 (first number), num2 (second number) and operation (a string representing the operation:
"add", "subtract", "multiply", "divide", "mod").
Using the match-case statement, perform the requested operation and print the result. If the operation
is not one of the valid options, print "Invalid operation".
Objective:
To write a Python program that uses match-case to perform basic arithmetic operations.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
num1 = float(input("Enter num1: "))
num2 = float(input("Enter num2: "))
operation = input("Enter operation (add, subtract, multiply, divide, mod): ")
match operation:
case "add":
print("Result:", num1 + num2)
case "subtract":
print("Result:", num1 - num2)
case "multiply":
print("Result:", num1 * num2)
case "divide":
if num2 != 0:
print("Result:", num1 / num2)
else:
print("Cannot divide by zero")
case "mod":
if num2 != 0:
print("Result:", num1 % num2)
else:
print("Cannot modulo divide by zero")
case _:
print("Invalid operation")
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 11:
Write a program to demonstrate the use of membership operators (in and not in) on the following
data types: String, List ,Tuple ,Dictionary ,Set .
The program should print whether the given element exists or does not exist in each data type.
Objective:
To show whether an element exists or does not exist in various data types using membership
operators.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
s = "hello"
lst = [1, 2, 3]
tup = (4, 5, 6)
dct = {'a': 1, 'b': 2}
st = {7, 8, 9}
element = input("Enter an element to check: ")
print("In string:", element in s)
print("In list:", int(element) in lst if [Link]() else False)
print("In tuple:", int(element) in tup if [Link]() else False)
print("In dictionary keys:", element in dct)
print("In set:", int(element) in st if [Link]() else False)
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 12:
Write a Python program that takes marks obtained by a student in an exam as input (0–100) and
prints the corresponding grade based on the following criteria using if-elif-else:
Marks ≥ 90 → Grade: A+
Marks ≥ 80 and < 90 → Grade: A
Marks ≥ 70 and < 80 → Grade: B
Marks ≥ 60 and < 70 → Grade: C
Marks ≥ 50 and < 60 → Grade: D
Marks < 50 → Grade: F
The program should also handle invalid input (marks less than 0 or greater than 100) by printing
"Invalid marks".
Objective:
To write Python code that maps marks to grade with input validation.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
marks = float(input("Enter marks (0-100): "))
if marks < 0 or marks > 100:
print("Invalid marks")
elif marks >= 90:
grade = "A+"
elif marks >= 80:
grade = "A"
elif marks >= 70:
grade = "B"
elif marks >= 60:
grade = "C"
elif marks >= 50:
grade = "D"
else:
grade = "F"
if 0 <= marks <= 100:
print("Grade:", grade)
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 13:
Write a program that takes a year as input from the user and determines whether it is a leap year or
not.
Objective:
To write Python code that checks leap year conditions.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
year = int(input("Enter year: "))
if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
print(f"{year} is a leap year")
else:
print(f"{year} is not a leap year")
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 14:
Write a program that takes an integer input from the user and determines whether the number is a
prime number or not.
Objective:
To write a Python program that checks primality of a number.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
n = int(input("Enter a number: "))
if n < 2:
print("Not a prime number")
else:
is_prime = True
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
is_prime = False
break
if is_prime:
print("Prime number")
else:
print("Not a prime number")
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 15:
Write a Python program that takes a positive integer as input and determines whether it is an
Armstrong number or not.
Objective:
To write Python code to identify Armstrong (narcissistic) numbers.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
n = int(input("Enter a positive integer: "))
num = n
order = len(str(n))
sum = 0
while num > 0:
digit = num % 10
sum += digit ** order
num //= 10
if sum == n:
print(f"{n} is an Armstrong number")
else:
print(f"{n} is not an Armstrong number")
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 16:
Write a Python program that takes an integer as input and checks whether it is a palindrome number
or not.
Objective:
To write Python code that determines if an integer is palindrome.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
num = input("Enter an integer: ")
if num == num[::-1]:
print(f"{num} is a palindrome number")
else:
print(f"{num} is not a palindrome number")
Output:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Problem statement 17:
Write a Python program that takes an integer as input and calculates the sum of its digits.
Objective:
To write Python code that calculates the sum of digits in an integer.
Pseudocode:
NAME: Piyush Kumar COURSE: BCA (AI and DS) ROLL NO: 2510610197
Python code:
num = int(input("Enter an integer: "))
total = 0
while num > 0:
total += num % 10
num //= 10
print("Sum of digits:", total)
Output: