0% found this document useful (0 votes)
41 views12 pages

X AI - Programs

Uploaded by

7D027 Nilaruna S
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)
41 views12 pages

X AI - Programs

Uploaded by

7D027 Nilaruna S
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
You are on page 1/ 12

Program 1:

AIM: Write a program to check whether the given character is an


uppercase letter or lowercase letter or a digit or a special character.
#Input the character to check

ch=input("Enter Any Character:")

'''Checking whether it is upperletter or lowerletter or digit or a special


character'''

if ch.isupper():

print(ch, " is an upper case letter")

elif ch.islower():

print(ch, " is a lower case letter")

elif ch.isdigit():

print(ch, " is a digit")

elif ch.isspace():

print(ch, " is a space")

else:

print(ch," is a special character")

RESULT: : Thus, the program to check whether the given character is an


uppercase letter or lowercase letter or a digit or a special character is
executed and verified successfully.

Program 2:
An electric power distribution company charges its domestic consumers
as follows:
Consumption Units Rate of Charge
0-100 Rs. 1 per unit
101-300 Rs. 100 plus Rs. 1.25 per unit in excess of 100
301-500 Rs. 350 plus Rs. 1.50 per unit in excess of 300
500 and above Rs. 650 plus Rs. 1.75 per unit in excess of 500
AIM: Write a program that read the customer number & power consumed
and prints the amount to be paid by the customer.

#Input Data
cno=int(input("Enter Cusumer Number:"))
pc=int(input("Enter power consumed:"))
#Computing bill amount based on power consumed
if pc>0 and pc<=100:
bill_amt=pc*1
elif pc>100 and pc<=300:
bill_amt=100+(pc-100)*1.25
elif pc>300 and pc<500:
bill_amt=350+(pc-300)*1.50
elif pc>500:
bill_amt=650+(pc-500)*1.75
else:
print("Invalid Power Consumed Units")
#Printing the bill in proper format
print("~"*60)
print("\t\tABC Power Company Ltd.")
print("~"*60)
print("Consumer Number:",cno)
print("Consumed Units:",pc)
print(" ")
print("Bill Amount:",bill_amt)
RESULT: Thus, the program that read the customer number & power
consumed and prints the amount to be paid by the customer is executed
and verified successfully.
Program 3:

AIM: Write a program to check whether the entered number is


Armstrong or not.

#Enter a number to check


n=int(input("Enter number to check:"))
#Store the original number into temporary variable
t=n
s=0
#Computing the sum of cube of each digit and iterating until n=0
while n!=0:
r=n%10
s=s+(r**3)
n//=10
#Checking & displaying whether armstrong or not
if t==s:
print(s," is Armstrong number")
else:
print (s," is not an Artmstrong number")

RESULT: Thus, the program to check whether the entered number is


Armstrong or not is executed and verified successfully.
Program 4:

AIM: Write a program to generate the following pattern:

2 3
6
4 5

7 8 9 10

11 12 13 14 15

#Take input for n lines

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

#Generating Pattern

k=1

for i in range(1,n+1):

for j in range(1,i+1):

print(k, end=" ")

k=k+1

print()

RESULT: Thus, the program to generate the following pattern is executed


and verified successfully.
PROGRAM : 5
AIM: Write a program to create a list of students marks with user-defined
values and find the maximum.

#Take input for n lines

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

#Creating empty list

l=[]

#Accepting marks and appending marks into the list

for i in range(n):

m=int(input("Enter marks:"))

l.append(m)

print("Maximum marks scored:",max(l))

RESULT: Thus, the program to create a list of students' marks with user-
defined values and find the maximum is Armstrong or not is executed and
verified successfully.

PROGRAM : 6
AIM: Write a program to create a list of numbers and swap the content with
the next value divisible by 5.

#Take input for no of subjects


n=int(input("Enter no. of subjects:"))
#Creating empty list
l=[]
#Accepting marks and appending marks into the list
for i in range(n):
m=int(input("Enter marks:"))
l.append(m) #Swaping elements
for i in range(len(l)):
if l[i] % 5 == 0:
l [ i ], l [i-1] = l [ i - 1 ] , l [i]
print("List after swap:",l)
RESULT: Thus, the program to create a list of numbers and swap the
content with the next value divisible by 5 is executed and verified
successfully.

PROGRAM : 7
AIM: Write a program to count the frequency of every element in a given
list.

#Creating empty list


l = []
#Take input for n no. of elements
n=int(input("Enter the no. of elements:"))
#Append the values into the list
for i in range(n):
val=int(input("Enter value "+str(i+1)+":"))
l.append(val)
#Decalring a dictionary object to store the data
f = {}
for i in l:
if (i in f):
f[i] += 1
else:
f[i] = 1
#Displaying the data
for i, j in f.items():
print(i, "", j)
RESULT: Thus, the program to count the frequency of every element in a
given list is executed and verified successfully.
DATA SCIENCE
PROGRAM: 8
AIM: Write a program to develop a matrix of 3x3 with values from
11 t0 28.

#Import NumPy Package


import numpy as np
#Creating array using arange() function
arr=np.arange(11,28,2)
#reshaping array for 2D
arr=arr.reshape(3,3)
#printing array
print(arr)

RESULT: Thus, the program to develop a matrix of 3x3 with values from
11 t0 28 is executed and verified successfully.

PROGRAM: 9
AIM: Write a program to convert a python list to a NumPy array.

#Import NumPy Package


import numpy as np
#Creating empty list
l = []
#Take input for n no. of elements
n=int(input("Enter the no. of elements:"))
#Append the values into the list
for i in range(n):
val=int(input("Enter value "+str(i+1)+":"))
l.append(val)
#Converting list into numpy array
arr=np.array(l)
print("Array:",arr)

RESULT: Thus, the program to convert a python list to a NumPy array is


executed and verified successfully.
PROGRAM: 10

AIM: Write a program to create a dataframe named player and store their
data in the columns like team, no. of matches, runs, and average. Assign
player name as row index and Display only those player details whose
score is more than 1000.
#import pandas package

import pandas as pd

#Creating Dictionary to store data

d={'Team':['India','Pakistan','England','Asutralia'],

'Matches':[25,23,19,17],

'Runs':[1120,1087,954,830],

'Average':[44.80,47.26,50.21,48.82]}

#Creating a dataframe

player=pd.DataFrame(d,index=['Virat kohli','Babar Azam','Ben

Stokes','Steve Smith'])

#Displaying data whose runs > 1000

print(player[player['Runs']>1000])

RESULT: Thus, the program to create a dataframe named player and store

their data in the columns like team, no. of matches, runs, and average is

executed and verified successfully.


PROGRAM: 11

AIM : Write a program to represent the data on the ratings of

mobile games on bar chart. The sample data is given as: Pubg,

FreeFire, MineCraft, GTA-V, Call of duty, FIFA 22. The rating

for each game is as: 4.5,4.8,4.7,4.6,4.1,4.3.

#Import package for Matplot Library

import matplotlib.pyplot as plt

#Creating lists for data

games=['Pubg', 'FreeFire', 'MineCraft', 'GTA-V','Call of duty', 'FIFA 22']

rating=[4.5,4.8,4.7,4.6,4.1,4.3]

#Creating bar graph with different bar colours

plt.bar(games,rating,color=['black', 'red', 'green', 'blue', 'yellow'])

#Customizing the bar graph

plt.title("Games Rating 2022")

plt.xlabel('Games')

plt.ylabel('Rating')

plt.legend();

plt.show()

RESULT: Thus, the program to represent the data on the ratings of


mobile games on bar chart is executed and verified successfully.
PROGRAM :12
AIM: Consider the following data of a clothes store and plot the data on
the line chart:
Month Jeans T-Shirts Shirts
March 1500 4400 6500
April 3500 4500 5000
May 6500 5500 5800
June 6700 6000 6300
July 6000 5600 6200
August 6800 6300 4500
Customize the chart as you wish.

#import package for line chart


import matplotlib.pyplot as pp
#creating list data
mon =['March','April','May','June','July','August']
jeans= [1500,3500,6500,6700,6000,6800]
ts = [4400,4500,5500,6000,5600,6300]
sh = [6500,5000,5800,6300,6200,4500]
#Creating Line chart
pp.plot(mon,jeans,label='Mask',color='g',linestyle='dashed', linewidth=4,\
marker='o', markerfacecolor='k', markeredgecolor='r')
pp.plot(mon,ts,label='Mask',color='b',linestyle='dashed', linewidth=4,\
marker='3', markerfacecolor='k', markeredgecolor='g')
pp.plot(mon,sh,label='Mask',color='r',linestyle='dashed', linewidth=4,\
marker='v', markerfacecolor='k', markeredgecolor='b')
#Cusotmizing plot
pp.title("Apna Garment Store")
pp.xlabel("Months")
pp.ylabel("Garments")
pp.legend()
pp.show()
RESULT: Thus, the program to represent the data of a clothes store and
plot the data on the line chart is executed and verified successfully.
PROGRAM : 13
AIM: Write a menu-driven program to calculate the mean, mode and
median for the given data:
[5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4]

#import statistics
import statistics
#Creating list
l=[5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4]
#Display mean, mode and median value using functions
print("Mean Value:%.2f"% statistics.mean(l))
print("Mode Value:%.2f"% statistics.mode(l))
print("Median Value:%.2f"% statistics.median(l))

RESULT: Thus, the program to calculate the mean, mode and median
for the given data is executed and verified successfully.

PROGRAM : 14

AIM: Write a program to calculate variance and standard


deviation for the given data:
[33,44,55,67,54,22,33,44,56,78,21,31,43,90,21,33,44,55,87]

#import statistics
import statistics
#Creating list
l=[33,44,55,67,54,22,33,44,56,78,21,31,43,90,21,33,44,55,87]
#Display varaince and standard deviation value using functions
print("Variance:%.2f"%statistics.variance(l))
print("Standard Deviation:%.2f"%statistics.stdev(l))

RESULT: Thus, the program to calculate variance and standard


deviation for the given data is executed and verified successfully.
INDEX
1 Write a program to check whether the given character is an uppercase
letter or lower case letter or a digit or a special character.
2 Write a program to read the customer number and power consumed and
prints the amount to be paid by the customer by using the given data.
3 Write a program to check whether the number is Armstrong or not.
4 Write a program to generate the following pattern using for loop.
5 Write a program to create a list of students’ marks with user-
defined values and find the maximum.
6 Write a program to create a list of numbers and swap the content
with the next value divisible by 5.
7 Write a program to count the frequency of every element in a
given list.
8 Write a program to create matrix of 3X3 from 11 to 28.
9 Write a program to convert a python list to a NumPy array.
10 Write a program to create a data frame named player and store their
data in the columns.
11 Write a program to represent the data on the ratings of mobile games on
bar chart.
12 Write a program to create a data of a clothes store and plot the data on
the line chart.
13 Write a program to calculate the mean, mode and median for the given
data
14 Write a program to calculate variance and standard deviation for the
given data
15 Try and write answer the below-mentioned questions on the basis of
online tools.
16 Create your own pixels on piskelapp (https://www.piskelapp.com/) and make
a gif image.
17 Do the following tasks in Opencv.

You might also like