X AI - Programs
X AI - Programs
if ch.isupper():
elif ch.islower():
elif ch.isdigit():
elif ch.isspace():
else:
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:
2 3
6
4 5
7 8 9 10
11 12 13 14 15
n=int(input("Enter n:"))
#Generating Pattern
k=1
for i in range(1,n+1):
for j in range(1,i+1):
k=k+1
print()
l=[]
for i in range(n):
m=int(input("Enter marks:"))
l.append(m)
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.
PROGRAM : 7
AIM: Write a program to count the frequency of every element in a given
list.
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.
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
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
Stokes','Steve Smith'])
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
mobile games on bar chart. The sample data is given as: Pubg,
rating=[4.5,4.8,4.7,4.6,4.1,4.3]
plt.xlabel('Games')
plt.ylabel('Rating')
plt.legend();
plt.show()
#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
#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))