Home | | Computer Science 12th Std | Python Programs using List

Python - Python Programs using List | 12th Computer Science : Chapter 9 : Python Modularity and OOPS : Lists, Tuples, Sets And Dictionary

Chapter: 12th Computer Science : Chapter 9 : Python Modularity and OOPS : Lists, Tuples, Sets And Dictionary

Python Programs using List

Python Programs using List

Programs using List


Program 1: write a program that creates a list of numbers from 1 to 20 that are divisible by 4

divBy4=[ ]

for i in range(21):

if (i%4==0):

divBy4.append(i)

print(divBy4)

Output

[0, 4, 8, 12, 16, 20]


Program 2: Write a program to define a list of countries that are a member of BRICS. Check whether a county is member of BRICS or not

country=["India", "Russia", "Srilanka", "China", "Brazil"]

is_member = input("Enter the name of the country: ")

if is_member in country:

print(is_member, " is the member of BRICS")

else:

print(is_member, " is not a member of BRICS")

Output

Enter the name of the country: India

India is the member of BRICS

Output

Enter the name of the country: Japan

Japan is not a member of BRICS


Program 3: Python program to read marks of six subjects and to print the marks scored in each subject and show the total marks

marks=[]

subjects=['Tamil', 'English', 'Physics', 'Chemistry', 'Comp. Science', 'Maths'] for i in range(6):

m=int(input("Enter Mark = "))

marks.append(m)

for j in range(len(marks)):

print("{ }. { } Mark = { } ".format(j1+,subjects[j],marks[j]))

print("Total Marks = ", sum(marks))

Output

Enter Mark = 45

Enter Mark = 98

Enter Mark = 76

Enter Mark = 28

Enter Mark = 46

Enter Mark = 15

1. Tamil Mark = 45

2. English Mark = 98

3. Physics Mark = 76

4. Chemistry Mark = 28

5. Comp. Science Mark = 46

6. Maths Mark = 15

Total Marks = 308


Program 4: Python program to read prices of 5 items in a list and then display sum of all the prices, product of all the prices and find the average

items=[]

prod=1

for i in range(5):

print ("Enter price for item { } : ".format(i+1))

p=int(input())

items.append(p)

for j in range(len(items)):

print("Price for item { } = Rs. { }".format(j+1,items[j]))

prod = prod * items[j]

print("Sum of all prices = Rs.", sum(items))

print("Product of all prices = Rs.", prod)

print("Average of all prices = Rs.",sum(items)/len(items))

Output:

Enter price for item 1 :

5

Enter price for item 2 :

10

Enter price for item 3 :

15

Enter price for item 4 :

20

Enter price for item 5 :

25

Price for item 1 = Rs. 5

Price for item 2 = Rs. 10

Price for item 3 = Rs. 15

Price for item 4 = Rs. 20

Price for item 5 = Rs. 25

Sum of all prices = Rs. 75

Product of all prices = Rs. 375000

Average of all prices = Rs. 15.0


Program 5: Python program to count the number of employees earning more than 1 lakh per annum. The monthly salaries of n number of employees are given

count=0

n=int(input("Enter no. of employees: "))

print("No. of Employees",n)

salary=[]

for i in range(n):

print("Enter Monthly Salary of Employee { } Rs.: ".format(i+1))

s=int(input())

salary.append(s)

for j in range(len(salary)):

annual_salary = salary[j] * 12

print ("Annual Salary of Employee { } is:Rs. { }".format(j+1,annual_salary))

if annual_salary >= 100000:

count = count + 1

print("{ } Employees out of { } employees are earning more than Rs. 1 Lakh per annum".

format(count, n))

Output:

Enter no. of employees: 5

No. of Employees 5

Enter Monthly Salary of Employee 1 Rs.:

3000

Enter Monthly Salary of Employee 2 Rs.:

9500

Enter Monthly Salary of Employee 3 Rs.:

12500

Enter Monthly Salary of Employee 4 Rs.:

5750

Enter Monthly Salary of Employee 5 Rs.:

8000

Annual Salary of Employee 1 is:Rs. 36000

Annual Salary of Employee 2 is:Rs. 114000

Annual Salary of Employee 3 is:Rs. 150000

Annual Salary of Employee 4 is:Rs. 69000

Annual Salary of Employee 5 is:Rs. 96000

2 Employees out of 5 employees are earning more than Rs. 1 Lakh per annum


Program 6: Write a program to create a list of numbers in the range 1 to 10. Then delete all the even numbers from the list and print the final list.

Num = []

for x in range(1,11):

Num.append(x)

print("The list of numbers from 1 to 10 = ", Num)

for index, i in enumerate(Num):

if(i%2==0):

del Num[index]

print("The list after deleting even numbers = ", Num)

Output

The list of numbers from 1 to 10 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] The list after deleting even numbers = [1, 3, 5, 7, 9]


Program 7: Write a program to generate in the Fibonacci series and store it in a list. Then find the sum of all values.

a=-1

b=1

n=int(input("Enter no. of terms: "))

i=0

sum=0

Fibo=[]

while i<n:

s = a + b

Fibo.append(s)

sum+=s

a = b

b = s

i+=1

print("Fibonacci series upto "+ str(n) +" terms is : " + str(Fibo))

print("The sum of Fibonacci series: ",sum)

Output

Enter no. of terms: 10

Fibonacci series upto 10 terms is : [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

The sum of Fibonacci series: 88

 

Tags : Python , 12th Computer Science : Chapter 9 : Python Modularity and OOPS : Lists, Tuples, Sets And Dictionary
Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
12th Computer Science : Chapter 9 : Python Modularity and OOPS : Lists, Tuples, Sets And Dictionary : Python Programs using List | Python


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.