0% found this document useful (0 votes)
511 views

Python Programs

The document contains Python code snippets for various tasks like checking voter eligibility, calculating student grades, printing patterns, finding sums and averages, working with lists and NumPy arrays, plotting charts from data, reading and displaying CSV and image files. A variety of programming concepts are demonstrated including loops, conditional statements, functions, lists, arrays, files and data visualization.

Uploaded by

Bhaskar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
511 views

Python Programs

The document contains Python code snippets for various tasks like checking voter eligibility, calculating student grades, printing patterns, finding sums and averages, working with lists and NumPy arrays, plotting charts from data, reading and displaying CSV and image files. A variety of programming concepts are demonstrated including loops, conditional statements, functions, lists, arrays, files and data visualization.

Uploaded by

Bhaskar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

'''#program to check if a person can vote

age=int(input("enter the age "))


if(age>18):
print("you are eligible for vote")
else:
print("you are not eligible for vote")
'''
'''WAP To print the grade of a student
m1=int(input('enter marks in eng subject out of 100'))
m2=int(input('enter marks in maths subject out of 100'))
m3=int(input('enter marks in science subject out of 100'))
m4=int(input('enter marks in comp subject out of 100'))
m5=int(input('enter marks in ssc subject out of 100'))
m6=int(input('enter marks in hindi subject out of 100'))
t=m1+m2+m3+m4+m5+m6
per=t/6
if per > 91:
print("grade A1")
elif per > 81:
print(" grade A2")
elif(per>71):
print("grade B1")
elif(per>61):
print('grade B2')
elif(per >51):
print("grade c1")
elif(per >41):
print(" grade c2")
elif(per<21 and per >0):
print("Fail")
'''
'''WAP to print pattern
for i in range(1,6):
print("* "*i)

for i in range(5,0,-1):
print("* "*i)
'''
'''WAP to print sum of first 10 natural numbers
n=0
for i in range(1,11):
n=n+i
print(n)
'''
'''WAP to print odd numbers from 1 to n
t=int(input("enter the value of t"))
for i in range(1,t):
if(i%2!=0):
print(i)
'''
'''
WAP to print first 10 even numbers
for i in range(1,11):
if(i%2==0):
print(i)
'''
'''
WAP to print first 10 natural numbers
for i in range(1,11):
print(i)
'''
'''WAP to input a number and check if the number is positive, negative or Zero and
display an appropriate message

n= int(input("enter the number of n"))


if(n>0):
print("Number is positive")
elif(n<0):
print("Number is negative")
else:
print("Number is Zero")
'''
'''
#Create a list in python of children selected for science quiz with following
names-Arjun,Sonakshi,Vikram,Sandhya,Sonal Isha,kartik
#perform the following tasks on the list in sequence-
#print the whole list
#Delete the name "Vikram" from the list
#Add the name "jay" at the end
#Remove the item which is at the second position
children_Name=['Arjun','Sonakshi','Vikram','Sandhya','Sonal' ,'Isha','kartik']
print(children_Name)
children_Name.remove("Vikram")
print(children_Name)
children_Name.append("Jay")
print(children_Name)
children_Name.pop(1)
print(children_Name)

#Create a list num=[23,12,5,9,65,44]


#print the length of the list
#print the element from second to fourth position using positive indexing
#print the element from position third to fifth using negative indexing
num=[23,12,5,9,65,44]
print(len(num))
print(num[1:4])
print(num[-4:-1])

#Create a list of 10 even numbers,add 1 to each list item and print the final list.
#add 5 at index no 4 in a list.
list_1=[2,4,6,8,10,12,14,16,18,20]
print(list_1)
for index in range(len(list_1)):
list_1[index]=list_1[index]+1
print(list_1)
list_1[4]=list_1[4]+5
print(list_1)
# Create a list List_1=[10,20,30,40].Add the elements[14,15,12] using extended
function.Now sort the final list in ascending order and print it.
list_1=[10,20,30,40]
print(list_1)
list_1.extend([14,15,12])
print(list_1)
list_1.sort()
print(list_1)

#program to find the sum of all given element list.


list_1=[1,2,3,4,5]
print(sum(list_1))

import numpy
rollno=numpy.array([1,2,3])
print(rollno)

import numpy as np
p=np.arange(10,101,10)
print(p)
a=np.random.random(4)
print(a)
b=np.random.randint(5,size=(3,6))
print(b)
a=[1,2,3,4,1,1,11,1,1]
b=[4,5,6,7,8,9,5,6,5,6,5,6,5,6,8]
if (len(a)>=len(b)):
for i in range (len(b)):
a[i]=(a[i]+b[i])
print(a)
else:
for i in range (len(a)):
b[i]=(b[i]+a[i])
print(b)

#Write a program to add the elements of the two lists.


import numpy as np
a=np.array([1,2,3,4])
b=np.array([2,3,4,5])
print(a,b)
print(a+b)

# Write a program to add the elements of the two lists with different size.
a=[1,2,3,4,1,1,11,1,1]
b=[4,5,6,7,8,9,5,6,5,6,5,6,5,6,8]
if (len(a)>=len(b)):
for i in range (len(b)):
a[i]=(a[i]+b[i])
print(a)
else:
for i in range (len(a)):
b[i]=(b[i]+a[i])
print(b)

#Write a program to display line chart from (2,5) and (9,10).

import matplotlib.pyplot as plt


import numpy as np
x=[2,9]
y=[5,10]
plt.plot(x,y)
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.title("line chart")
plt.show()

#Write a program to display a scatter chart for the following points(2,5),(9,10),


(8,3),(5,7),(6,18).
import matplotlib.pyplot as plt
import numpy as np
x=[2,9,8,5,6]
y=[5,10,3,7,18]
plt.scatter(x,y,marker=".")
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.title("scatter chart")
plt.show()

#Read csv file saved in your system and display 10 rows.

import pandas as pd
x=int(input("enter the number of rows which u you want to access"));
p=pd.read_csv("C:\\Users\\user27\\Desktop\\salary.csv",nrows=x)
print(p)

#Read csv file saved in your system and display its information.

import pandas as pd
p=pd.read_csv("C:\\Users\\user27\\Desktop\\salary.csv")
print(p)

#write a program to calculate mean, median,mode .


import numpy as np
import statistics
a = [12,1,1,1,1]
print(statistics.mode(a))
print(statistics.median(a))
print(statistics.mean(a))'''
'''
#Write a proram to read an image and display using python
import cv2
import numpy as np
from matplotlib import pyplot as plt
img=cv2.imread("C:\\Users\\user27\\Desktop\\dog.jpg")
plt.imshow(img)
plt.axis('off')
plt.show()
'''

You might also like