0% found this document useful (0 votes)
5 views13 pages

Class 11 Project

The document contains a list of 20 programming exercises, each with a brief description and code examples in Python. The exercises cover various topics such as arithmetic operations, string manipulation, list operations, and number theory. Each program includes sample input and output to illustrate functionality.

Uploaded by

supratimstars
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views13 pages

Class 11 Project

The document contains a list of 20 programming exercises, each with a brief description and code examples in Python. The exercises cover various topics such as arithmetic operations, string manipulation, list operations, and number theory. Each program includes sample input and output to illustrate functionality.

Uploaded by

supratimstars
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Serial Page Teacher’s

Topic
No. No. Signature

1. Program–1: Menu-driven calculator (+, -, *, /) 1

Program–2: Check whether a number is prime


2. 1
or not

Program–3: Generate Fibonacci series up to n


3. 2
terms

Program–4: Count vowels, consonants, digits


4. 2
and spaces in a string

Program–5: Find the largest and smallest


5. 3
number in a list

Program–6: Remove duplicates from a list


6. 3
(display before/after)

Program–7: Find the factorial of a number


7. 4
using loop

Program–8: Check whether a string/number is


8. 4
a palindrome

Program–9: Count even, odd, positive and


9. 5
negative numbers in a list

Program–10: Generate a number pyramid


10. 5
pattern

Program–11: Sort a list without using built-in


11. 6
sort() function

Program–12: Count frequency of each element


12. 6
in a list

Program–13: Find the second largest number in


13. 7
a list

Program–14: Accept student records and


14. 7
display the result

Program–15: Find the sum and average of


15. 8
elements in a list

Program–16: Display all prime numbers within


16. 8
a given range
Serial Page Teacher’s
Topic
No. No. Signature

Program–17: Check whether a number is an


17. 9
Armstrong number

Program–18: Reverse each word in a given


18. 9
string

Program–19: Find GCD and LCM of two


19. 10
numbers

20. Program–20: Generate Floyd’s triangle 10


Program–1: Menu-Driven Calculator
Code:-
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")

choice = int(input("Enter your choice: "))


a = float(input("Enter first number: "))
b = float(input("Enter second number: "))

if choice == 1:
print("Result =", a + b)
elif choice == 2:
print("Result =", a - b)
elif choice == 3:
print("Result =", a * b)
elif choice == 4:
if b != 0:
print("Result =", a / b)
else:
print("Division by zero not allowed")
else:
print("Invalid choice")

Output:-
Enter your choice: 3
Enter first number: 6
Enter second number: 5
Result = 30.0

Program–2: Prime Number


Code:-
n = int(input("Enter a number: "))
if n > 1:
for i in range(2, n):
if n % i == 0:
print("Not Prime")
break
else:
print("Prime Number")
else:
print("Not Prime")
Output:-
Enter a number: 11

Prime Number

Program–3: Fibonacci Series


Code:-
n = int(input("Enter number of terms: "))
a, b = 0, 1
for i in range(n):
print(a, end=" ")
a, b = b, a + b

Output:-
Enter number of terms: 6
0 1 1 2 3 5

Program–4: Count Vowels, Consonants, Digits, Spaces


Code:-
s = input("Enter a string: ")
v = c = d = sp = 0

for ch in s:
if [Link]() in "aeiou":
v += 1
elif [Link]():
c += 1
elif [Link]():
d += 1
elif [Link]():
sp += 1

print("Vowels:", v)
print("Consonants:", c)
print("Digits:", d)
print("Spaces:", sp)

Output:-
Enter a string: Hello 123
Vowels: 2
Consonants: 3
Digits: 3
Spaces: 1
Program–5: Largest & Smallest in List
Code:-
lst = [12, 4, 25, 7]
print("Largest =", max(lst))
print("Smallest =", min(lst))

Output:-
Largest = 25
Smallest = 4

Program–6: Remove Duplicates (Before & After)


Code:-
lst = ['a', 'b', 'a', 'c', 'b']
print("Original list:", lst)

new = []
for i in lst:
if i not in new:
[Link](i)

print("After removing duplicates:", new)

Output:-
Original list: ['a', 'b', 'a', 'c', 'b']
After removing duplicates: ['a', 'b', 'c']

Program–7: Factorial
Code
n = int(input("Enter a number: "))
fact = 1
for i in range(1, n+1):
fact *= i
print("Factorial =", fact)

Output
Enter a number: 5
Factorial = 120
Program–8: Palindrome:-
Code:-
s = input("Enter string or number: ")
if s == s[::-1]:
print("Palindrome")
else:
print("Not Palindrome")

Output:-
Enter string: level
Palindrome

Program–9: Count Even, Odd, Positive, Negative


Code:-
lst = [-2, 3, 4, -5, 6]
even = odd = pos = neg = 0

for n in lst:
if n % 2 == 0:
even += 1
else:
odd += 1
if n > 0:
pos += 1
elif n < 0:
neg += 1

print("Even:", even)
print("Odd:", odd)
print("Positive:", pos)
print("Negative:", neg)

Output:-
Even: 3
Odd: 2
Positive: 3
Negative: 2
Program–10: Number Pyramid Pattern
Code:-
rows = 4
for i in range(1, rows+1):
print(" "*(rows-i), end="")
for j in range(1, i+1):
print(j, end="")
for j in range(i-1, 0, -1):
print(j, end="")
print()

Output:-
1
121
12321
1234321

Program–11: Sort Without sort()


Code:-
lst = [5, 2, 8, 1]
for i in range(len(lst)):
for j in range(i+1, len(lst)):
if lst[i] > lst[j]:
lst[i], lst[j] = lst[j], lst[i]

print("Sorted list:", lst)

Output:-
Sorted list: [1, 2, 5, 8]

Program–12: Frequency Without Dictionary


Code:-
lst = ['apple', 'banana', 'apple', 'mango']
checked = []

for i in lst:
if i not in checked:
print(i, ":", [Link](i))
[Link](i)
Output:-
apple : 2

banana : 1
mango : 1

Program–13: Second Largest


Code:-
lst = [10, 5, 20, 15]
[Link]()
print("Second largest =", lst[-2])

Output:-
Second largest = 15

Program–14: Student Records


Code:-
n = int(input("Enter number of students: "))

for i in range(n):

print("\nEnter details of student", i + 1)

roll = input("Roll Number: ")

name = input("Name: ")

m1 = int(input("Marks in Subject 1: "))

m2 = int(input("Marks in Subject 2: "))

m3 = int(input("Marks in Subject 3: "))

total = m1 + m2 + m3

percentage = total / 3

if percentage >= 90:

grade = "A"
elif percentage >= 75:

grade = "B"

elif percentage >= 60:

grade = "C"

elif percentage >= 40:

grade = "D"

else:

grade = "F"

print("\n--- Result ---")

print("Roll Number :", roll)

print("Name :", name)

print("Total Marks :", total)

print("Percentage :", percentage)

print("Grade :", grade)

Output:-
Enter number of students: 1

Enter details of student 1


Roll Number: 12
Name: Rivu
Marks in Subject 1: 85
Marks in Subject 2: 78
Marks in Subject 3: 92

--- Result ---


Roll Number : 12
Name : Rivu
Total Marks : 255
Percentage : 85.0
Grade : B

Program–15: Sum & Average


Code:-
lst = [10, 20, 30]
print("Sum =", sum(lst))
print("Average =", sum(lst)/len(lst))
Output:-
Sum = 60
Average = 20.0

Program–16: Prime Numbers in Range


Code:-

for n in range(10, 21):


for i in range(2, n):
if n % i == 0:
break
else:
print(n, end=" ")

Output:-
11 13 17 19

Program–17: Armstrong Number


Code:-
n = int(input(“Enter no.:”)
temp = n
s = 0

while temp > 0:


d = temp % 10
s += d**3
temp //= 10

if s == n:
print("Armstrong Number")
else:
print("Not Armstrong")

Output:-
Enter no.:153

Armstrong Number
Program–18: Reverse Each Word
Code:-
s = "Hello World"
for w in [Link]():
print(w[::-1], end=" ")

Output:-
olleH dlroW

Program–19: Calculate GCD & LCM


Code:-
a, b = 12, 18
x, y = a, b

while y:
x, y = y, x % y

print("GCD =", x)
print("LCM =", (a*b)//x)

Output:-
GCD = 6
LCM = 36

Program–20: Floyd’s Triangle


Code:-
num = 1
for i in range(1, 5):
for j in range(i):
print(num, end=" ")
num += 1
print()
Output:-

1
23
456
7 8 9 10

You might also like