Python Computer Project
1. WAP to check whether a string is a palindrome or not.
Source Code:
Output:
2. WAP that reads a line, counts the words and displays the number of words.
Source Code:
Output:
3. WAP to capitalize every other letter in a string.
Source Code:
Output:
4. WAP to count occurrences of substring 'is'.
Source Code:
Output:
5. WAP to remove vowels from a string.
Source Code:
Output:
6. WAP to count words starting with a vowel.
Source Code:
Output:
7. WAP to sum digits present in a string.
Source Code:
Output:
8. WAP to find longest substring having only consonants.
Source Code:
Output:
9. WAP to display frequency chart (upper, lower, alphabets, digits).
Source Code:
Output:
10. WAP to find second largest element in a list.
Source Code:
Output:
11. WAP to add even numbers to list till user limit.
Source Code:
Output:
12. WAP to count occurrence of a number in list.
Source Code:
Output:
13. WAP to perform Linear Search.
Source Code:
Output:
14. WAP to delete odd and negative numbers from list.
Source Code:L1 = [1, 2, -9, 11, 22, -6, 3, 4]
new_list = []
for i in L1:
if i > 0 and i % 2 == 0:
new_list.append(i)
print("Updated List:", new_list)
Output:
15. WAP to delete duplicate elements from list.
Source Code:L1 = [5, 2, 4, 5, 12, 2, 7, 4]
new_list = []
for i in L1:
if i not in new_list:
new_list.append(i)
print("List after deleting duplicates:", new_list)
Output:
16. WAP to find sum of numbers ending with 3.
Source Code:L = [33, 13, 92, 99, 3, 12]
sum_val = 0
for i in L:
if i % 10 == 3:
sum_val += i
print("Sum of values ending with 3:", sum_val)
Output:
17. WAP to swap element with next element divisible by 7.
Source Code:Num = [3, 21, 5, 6, 14, 8, 14, 3]
for i in range(len(Num) - 1):
if Num[i + 1] % 7 == 0:
Num[i], Num[i + 1] = Num[i + 1], Num[i]
print("Resultant List:", Num)
Output:
18. WAP to exchange first half with second half of list.
Source Code:L1 = [10, 20, 30, 40, 50, 60, 70]
n = len(L1) // 2
L1 = L1[n:-1] + L1[:n] + [L1[-1]]
print("Updated List:", L1)
Output:
19. WAP to square integers and change case of strings.
Source Code:L = [10, "FUN", 40, "FEW", 50, "FULL"]
new_list = []
for i in L:
if type(i) == int:
new_list.append(i * i)
else:
new_list.append([Link]())
print("Updated List:", new_list)
Output:
20. WAP to display unique and duplicate elements.
Source Code:L = [2, 7, 1, 4, 9, 5, 1, 4, 3]
unique = []
duplicate = []
for i in L:
if i not in unique:
[Link](i)
elif i not in duplicate:
[Link](i)
print("Unique elements are:", unique)
print("Duplicate elements are:", duplicate)
Output:
21. WAP to display strings starting with A or a.
Source Code:L = []
while True:
print("\nMENU")
print("1. Append element")
print("2. Insert element")
print("3. Append a list")
print("4. Modify element")
print("5. Delete by position")
print("6. Delete by value")
print("7. Sort ascending")
print("8. Sort descending")
print("9. Search element")
print("10. Maximum element")
print("11. Minimum element")
print("12. Count element")
print("13. Reverse list")
print("14. Display list")
print("15. Exit")
ch = int(input("Enter choice: "))
if ch == 1:
[Link](int(input("Enter element: ")))
elif ch == 2:
pos = int(input("Enter position: "))
val = int(input("Enter value: "))
[Link](pos, val)
elif ch == 3:
lst = list(map(int, input("Enter list elements: ").split()))
[Link](lst)
elif ch == 4:
pos = int(input("Enter position: "))
val = int(input("Enter new value: "))
L[pos] = val
elif ch == 5:
pos = int(input("Enter position: "))
[Link](pos)
elif ch == 6:
val = int(input("Enter value: "))
[Link](val)
elif ch == 7:
[Link]()
elif ch == 8:
[Link](reverse=True)
elif ch == 9:
val = int(input("Enter value: "))
print("Found" if val in L else "Not Found")
elif ch == 10:
print("Maximum:", max(L))
elif ch == 11:
print("Minimum:", min(L))
elif ch == 12:
val = int(input("Enter value: "))
print("Count:", [Link](val))
elif ch == 13:
[Link]()
elif ch == 14:
print("List:", L)
elif ch == 15:
break
else:
print("Invalid Choice")
Output:
22. Menu driven program for list operations.
Source Code:
Output: