0% found this document useful (0 votes)
2 views2 pages

Programs

The document outlines various Python programming tasks involving lists, tuples, strings, and dictionaries. It includes functionalities such as creating, updating, searching, and counting elements, as well as calculating sums, averages, minimums, and maximums. Additionally, it covers counting specific character types, such as vowels, consonants, uppercase, lowercase, digits, and special symbols.

Uploaded by

akshat1949
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)
2 views2 pages

Programs

The document outlines various Python programming tasks involving lists, tuples, strings, and dictionaries. It includes functionalities such as creating, updating, searching, and counting elements, as well as calculating sums, averages, minimums, and maximums. Additionally, it covers counting specific character types, such as vowels, consonants, uppercase, lowercase, digits, and special symbols.

Uploaded by

akshat1949
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

LIST PROGRAMS val = int(input("Enter new print("Sum:", s)

Create List value: "))


L[pos] = val Min and Max
n = int(input("Enter number of elements: print("Updated List:", L)
")) mn = T[0]
L = [] Replace Element mx = T[0]
for i in range(n): for i in T:
[Link](int(input("Enter element: "))) old = int(input("Enter if i < mn:
print("List:", L) element to replace: ")) mn = i
new = int(input("Enter new if i > mx:
Display List element: ")) mx = i
for i in range(len(L)): print("Min:", mn)
for i in L: if L[i] == old: print("Max:", mx)
print(i) L[i] = new STRING PROGRAMSs = input("Enter
print("List after replace:", L) string: ")
Search Element
TUPLE PROGRAMS Search Character
x = int(input("Enter element to search: "))
found = False # Create Tuple ch = input("Enter character to search: ")
for i in L: n = int(input("Enter number found = False
if i == x: of elements: ")) for i in s:
found = True temp = [] if i == ch:
break for i in range(n): found = True
if found: [Link](int(input("Enter break
print("Element found") element: "))) if found:
else: T = tuple(temp) print("Character found")
print("Element not found") print("Tuple:", T) else:
print("Character not found")
Count Element Display Tuple
● Count Letters
c=0 for i in T:
for i in L: print(i) letters = 0
if i == x: for i in s:
c += 1 Search Element if [Link]():
print("Count:", c) letters += 1
x = int(input("Enter element print("Letters:", letters)
Sum and Average to search: "))
found = False Count Digits
s=0 for i in T:
for i in L: if i == x: digits = 0
s += i found = True for i in s:
avg = s / len(L) break if [Link]():
print("Sum:", s) if found: digits += 1
print("Average:", avg) print("Element found") print("Digits:", digits)
else:
Min and Max print("Element not found") Count Uppercase and Lowercase

mn = L[0] Count Element u=l=0


mx = L[0] for i in s:
for i in L: c=0 if [Link]():
if i < mn: for i in T: u += 1
mn = i if i == x: elif [Link]():
if i > mx: c += 1 l += 1
mx = i print("Count:", c) print("Uppercase:", u)
print("Min:", mn) print("Lowercase:", l)
print("Max:", mx) Sum
Count Spaces
Update Element s=0
for i in T: spaces = 0
pos = int(input("Enter position: ")) s += i for i in s:
if i == ' ':
spaces += 1 s=0
print("Spaces:", spaces) for k in d:
s += d[k]
Count Vowels and Consonants avg = s / len(d)
print("Sum:", s)
v=c=0 print("Average:", avg)
for i in [Link]():
if [Link](): Min and Max Value
if i in 'aeiou':
v += 1 values = list([Link]())
else: mn = values[0]
c += 1 mx = values[0]
print("Vowels:", v) for i in values:
print("Consonants:", c) if i < mn:
mn = i
Count Special Symbols if i > mx:
mx = i
sp = 0 print("Min:", mn)
for i in s: print("Max:", mx)
if not [Link]() and i != ' ':
sp += 1 Update Value
print("Special symbols:", sp)
DICTIONARY PROGRAMS key = input("Enter key to
update: ")
# Create Dictionary val = int(input("Enter new
d = {} value: "))
n = int(input("Enter number of items: ")) for k in d:
for i in range(n): if k == key:
k = input("Enter key: ") d[k] = val
v = int(input("Enter value: ")) print("Updated Dictionary:",
d[k] = v d)
print("Dictionary:", d)

Display Dictionary Delete Key

for k in d: key = input("Enter key to


print(k, ":", d[k]) delete: ")
for k in list([Link]()):
Search Key if k == key:
del d[k]
key = input("Enter key to search: ") print("Dictionary after
found = False deletion:", d)
for k in d:
if k == key:
found = True
break
if found:
print("Key found")
else:
print("Key not found")

Count Keys

count = 0
for k in d:
count += 1
print("Total keys:", count)

Sum and Average of Values

You might also like