0% found this document useful (0 votes)
6 views3 pages

Python Programs for List Operations

The document contains a series of Python programs that perform various tasks such as counting and summing positive and negative integers, counting vowels and consonants, transferring odd numbers to a new list, and reversing lists. Each program includes user input for a list of integers or characters and outputs the results based on specific criteria. The document serves as a practical guide for implementing basic programming concepts in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Python Programs for List Operations

The document contains a series of Python programs that perform various tasks such as counting and summing positive and negative integers, counting vowels and consonants, transferring odd numbers to a new list, and reversing lists. Each program includes user input for a list of integers or characters and outputs the results based on specific criteria. The document serves as a practical guide for implementing basic programming concepts in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SET – C : Python Programs

1. Program to count positive odd, positive even, negative odd, negative even and zeros in a list

lst = []
for i in range(10):
[Link](int(input("Enter integer: ")))

po = pe = no = ne = z = 0

for n in lst:
if n == 0:
z += 1
elif n > 0 and n % 2 == 0:
pe += 1
elif n > 0 and n % 2 != 0:
po += 1
elif n < 0 and n % 2 == 0:
ne += 1
else:
no += 1

print("Positive Odd:", po)


print("Positive Even:", pe)
print("Negative Odd:", no)
print("Negative Even:", ne)
print("Zeros:", z)

2. Program to find the sum of positive odd, positive even, negative odd, negative even and zeros

lst = []
for i in range(10):
[Link](int(input("Enter integer: ")))

spo = spe = sno = sne = sz = 0

for n in lst:
if n == 0:
sz += n
elif n > 0 and n % 2 == 0:
spe += n
elif n > 0 and n % 2 != 0:
spo += n
elif n < 0 and n % 2 == 0:
sne += n
else:
sno += n

print("Sum Positive Odd:", spo)


print("Sum Positive Even:", spe)
print("Sum Negative Odd:", sno)
print("Sum Negative Even:", sne)
print("Sum Zeros:", sz)

3. Program to find sum of decimal parts and count pure integers

lst = []
for i in range(10):
[Link](float(input("Enter number: ")))

decimal_sum = 0
int_count = 0

for n in lst:
if n == int(n):
int_count += 1
else:
decimal_sum += n - int(n)

print("Sum of decimal parts:", decimal_sum)


print("Count of pure integers:", int_count)

4. Program to count vowels, consonants and other characters


lst = []
for i in range(10):
[Link](input("Enter character: "))

v = c = o = 0

for ch in lst:
if [Link]():
if [Link]() in "aeiou":
v += 1
else:
c += 1
else:
o += 1

print("Vowels:", v)
print("Consonants:", c)
print("Others:", o)

5. Program to find sum of values at odd index

lst = []
for i in range(10):
[Link](int(input("Enter integer: ")))

s = 0
for i in range(1, len(lst), 2):
s += lst[i]

print("Sum of odd index values:", s)

6. Program to transfer odd numbers to a new list

lst = []
for i in range(10):
[Link](int(input("Enter integer: ")))

odd_list = []
for n in lst:
if n % 2 != 0:
odd_list.append(n)

print("Original List:", lst)


print("Odd List:", odd_list)

7. Program to swap alternate values in a list

lst = []
for i in range(10):
[Link](int(input("Enter integer: ")))

for i in range(0, len(lst)-1, 2):


lst[i], lst[i+1] = lst[i+1], lst[i]

print("Resultant List:", lst)

8. Program to swap first half with second half of the list

lst = []
for i in range(10):
[Link](int(input("Enter integer: ")))

mid = len(lst) // 2
lst = lst[mid:] + lst[:mid]

print("Resultant List:", lst)

9. Program to find frequency of a data item (without predefined function)

lst = []
for i in range(10):
[Link](int(input("Enter integer: ")))

item = int(input("Enter item to find frequency: "))


count = 0

for n in lst:
if n == item:
count += 1

print("Frequency:", count)

10. Program to find index of a specific data item (without predefined function)

lst = []
for i in range(10):
[Link](int(input("Enter integer: ")))

item = int(input("Enter item to find index: "))

for i in range(len(lst)):
if lst[i] == item:
print("Index:", i)
break
else:
print("Item not found")

11. Program to reverse a list (without predefined function and slicing)

lst = []
for i in range(10):
[Link](int(input("Enter integer: ")))

rev = []
for i in range(len(lst)-1, -1, -1):
[Link](lst[i])

print("Reversed List:", rev)

12. Program to generate first 25 Fibonacci numbers

fib = [0, 1]

for i in range(23):
[Link](fib[-1] + fib[-2])

print("Fibonacci Series:", fib)

13. Program to transfer negative odd numbers into a new list

lst = []
for i in range(10):
[Link](int(input("Enter integer: ")))

neg_odd = []
for n in lst:
if n < 0 and n % 2 != 0:
neg_odd.append(n)

print("Original List:", lst)


print("Negative Odd List:", neg_odd)

You might also like