0% found this document useful (0 votes)
3 views20 pages

Python File

The document contains a series of Python programming exercises, including tasks such as printing even numbers from a list, generating a multiplication table, checking voting eligibility based on age, and determining if a number is positive, negative, or zero. It also includes list manipulation examples like adding and removing elements, as well as visualizations using Matplotlib for line charts, bar charts, scatter charts, and pie charts. Additionally, there are examples of using OpenCV for image display and conversion to grayscale.
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)
3 views20 pages

Python File

The document contains a series of Python programming exercises, including tasks such as printing even numbers from a list, generating a multiplication table, checking voting eligibility based on age, and determining if a number is positive, negative, or zero. It also includes list manipulation examples like adding and removing elements, as well as visualizations using Matplotlib for line charts, bar charts, scatter charts, and pie charts. Additionally, there are examples of using OpenCV for image display and conversion to grayscale.
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

PYTHON FILE

Q1 Write a program to print even numbers in a list.

num=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20]
for i in range (0,len(num)):
if num[i]%==0:
print(num[i],’even’)
else:
print(num[i],’odd’)

Q2 Write a program to print a multiplication table of


the entered number.
num = int(input("Enter the number: "))

print("Multiplication Table of", num)


for i in range(1, 11):
print(num,"X",i,"=",num * i)

output:
Q3 Write a program to find the eligibility of a person for
voting if else.

age = int(input("Enter age : "))

if age >= 18:


print("Eligible for Voting!")
else:
print("Not Eligible for Voting!")

output:

Q4 Write a program to Check if a Number is Positive,


Negative or 0 .
num = float(input("Enter a number: "))
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")

output:

Q5 Write a program to Adding an element in List

list1 = ["a", "b", "c", "d"]


print ("Original list: ", list1)
[Link]('e')
print ("List after appending: ", list1)

Output:

Q6 Write a program to Delete an element in List.

thislist = ["apple", "banana", "cherry"]


print (thislist)
[Link]("banana")
print("after removing banana",thislist)

output:

Q7 Write a program to display a Line chart.


import [Link] as plt
week=[1,2,3,4]
prices=[40,80,100,50]
[Link]('Week')
[Link]('Apple prices')
[Link](week, prices,'r',linewidth=4,linestyle='dashdot')
[Link]()
[Link]()

output:
Q8 Write a program to display a bar chart.

import [Link] as plt


x=['english','hindi','science']
y=[89,76,95]
[Link](x,y,width=.5,color=['red','purple','teal'])
[Link](axis='both',linestyle='dotted',linewidth='2',colo
r='green')
[Link](0,100)
[Link]('subject')
[Link]('marks')
[Link]('bikash')
[Link]()
output:
Q9 Write a program to display a Scatter chart.

import [Link] as plt


x=['english','hindi','science']
y=[89,76,95]
[Link](x,y,color=['red','purple','teal'],marker='o',lin
ewidths=2)
[Link](axis='both')
[Link]('x axis')
[Link]('y axis')
[Link]('graph')
[Link]()

output:
Q10 Write a program to display a Pie chart.
import [Link] as plt
y=[56,98,39,76]
mylabels = ['apples','cherries','dates','bananas']
[Link](y,labels=mylabels,startangle=90,shadow=True,
explode=[0.4,0,0,0],autopct='%.2f')
[Link]()
[Link]

Q11
import cv2
img = [Link]("[Link]", cv2.IMREAD_COLOR)

[Link]('main',img)
[Link](0)
[Link]()

Q12
import cv2
image = [Link]("[Link]", cv2.IMREAD_COLOR)
gray_image = [Link](image,
cv2.COLOR_BGR@GRAY)
[Link]('main', gray_image)

[Link]('main'gray_img)
[Link](0)
[Link]()

You might also like