0% found this document useful (0 votes)
7 views18 pages

AI Practical 05

The document contains a list of programming exercises primarily focused on Python, covering various topics such as character classification, finding maximum numbers, checking Armstrong numbers, list operations, and data visualization using libraries like NumPy and Matplotlib. Each exercise includes a brief description and a sample code snippet. The exercises aim to enhance programming skills by applying concepts in practical scenarios.
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)
7 views18 pages

AI Practical 05

The document contains a list of programming exercises primarily focused on Python, covering various topics such as character classification, finding maximum numbers, checking Armstrong numbers, list operations, and data visualization using libraries like NumPy and Matplotlib. Each exercise includes a brief description and a sample code snippet. The exercises aim to enhance programming skills by applying concepts in practical scenarios.
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/ 18

‭LIST OF PRACTICALS‬

‭ . Write a program to check whether the given character is an uppercase letter or lowercase‬
1
‭letter or a digit or a special character‬

‭2. Write a program to find the maximum number out of the given three numbers.‬

‭3. Write a program to check whether the given number is Armstrong or not.‬

‭4. Write a program to add the elements of two Lists accepted from the user.‬

‭5. Write a program to count the frequency of every element in a given list.‬

‭ . Write a program to create a list of students’ marks with user-defined values and find the‬
6
‭maximum.‬

‭7. Write a python program to display the pattern .‬

‭8. Write a program to create a 2D array using NumPy.‬

‭9. Write a program to convert a python list to a NumPy array.‬

‭ 0. Write a program to calculate mean, median and mode using Numpy for the following‬
1
‭data [5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4] .‬

‭ 1. Write a program to display a scatter chart for the following points (2,5), (9,10), (8,3),‬
1
‭(5,7), (6,18).‬

‭ 2. Write a program to represent the data on the ratings of mobile games on a bar chart. The‬
1
‭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‬

‭ 3. Observe the given data for monthly sales of one of the salesmen for 6 months. Plot them‬
1
‭on the line chart. Month January February March April May June‬
‭Sales 2500 2100 1700 3500 3000 3800‬

‭14. Write a program to read an image and display using Python‬

‭15. Write a program to read an image and identify its shape using Python.‬
‭ 1.Write a program to check whether the given‬
Q
‭character is an uppercase letter or lowercase letter or a‬
‭digit or a special character.‬

‭ rogram‬
P
‭char = input("Enter a character: ")‬
‭if 'A' <= char <= 'Z':‬
‭print("Uppercase Letter")‬
‭elif 'a' <= char <= 'z':‬
‭print("Lowercase Letter")‬
‭elif '0' <= char <= '9':‬
‭print("Digit")‬
‭else:‬
‭print("Special Character")‬

‭Output‬
‭ 2.Write a program to find the maximum number out of‬
Q
‭the given three numbers‬

‭ rogram‬
P
‭num1 = int(input("Enter the first number: "))‬
‭num2 = int(input("Enter the second number: "))‬
‭num3 = int(input("Enter the third number: "))‬
‭if num1 >= num2 and num1 >= num3:‬
‭print(num1, "is greatest")‬
‭elif num2 >= num1 and num2 >= num3:‬
‭print(num2, "is greatest")‬
‭else:‬
‭print(num3, "is greatest")‬
‭Output‬
‭ 3.Write a program to check whether the given number‬
Q
‭is Armstrong or not. An Armstrong number is equal to‬
‭the sum of its digits each raised to the power of the‬
‭number of digits.‬

‭ rogram‬
P
‭num = int(input("Enter the number: "))‬
‭temp = num sum = 0‬
‭while (num>0):‬
‭rev = num%10‬
‭sum = sum + rev**3‬
‭num = num//10‬
‭if(temp == sum):‬
‭print("Armstrong Number")‬
‭else:‬
‭print("Not an armstrong number")‬
‭Output‬
‭ 4 Write a program to add the elements of two Lists‬
Q
‭accepted from the user.‬

‭ rogram‬
P
‭list1 = eval(input("Enter the elements of the first list: "))‬
‭list2 = eval(input("Enter the elements of the second list: "))‬
‭if len(list1) != len(list2):‬
‭print("The lists must be of the same length")‬
‭list3 = []‬

‭for i in range(len(list1)):‬
‭list3.append(list1[i] + list2[i])‬

‭ rint(list3)‬
p
‭Output‬
‭ 5 Write a program to count the frequency of every‬
Q
‭element in a given list.‬

‭ rogram‬
P
‭L = eval(input("Enter the elements of the list, separated by‬
‭space: "))‬
‭D = {} #empty dictionary‬
‭for item in L:‬
‭count = 0‬
‭if item in D:‬
‭D[item] += 1‬
‭else:‬
‭D[item] = 1‬
‭print("Lists elements Frequency :", D)‬

‭Output‬
‭ 6. Write a program to create a list of students’ marks‬
Q
‭with user-defined values and find the maximum.‬

‭ rogram‬
P
‭num_students = int(input("Enter the number of students: "))‬
‭marks = []‬
‭for i in range(num_students):‬
‭mark = float(input("Enter the marks of student: "))‬
‭marks.append(mark)‬
‭max_mark = marks[0]‬
‭for mark in marks:‬
‭if mark > max_mark:‬
‭max_mark = mark‬
‭print("Maximum marks: ", max_mark)‬

‭Output‬
‭ 7 Write a python program to display the following‬
Q
‭pattern :‬

‭ rogram a‬
P
‭rows = 5‬
‭for r in range(1, rows + 1):‬
‭for c in range(r):‬
‭print("*", end="")‬
‭print()‬

‭Output‬

‭ rogram b‬
P
‭rows = 5‬
‭for r in range(1, rows + 1):‬
‭for c in range(1, r + 1):‬
‭print(c, end=" ")‬
‭print()‬
‭Output‬
‭Q8 Write a program to create a 2D array using NumPy‬

‭ rogram‬
P
‭import numpy as np‬
‭array_2d = np.array([[1, 2, 3],‬
‭[4, 5, 6],‬
‭[7, 8, 9]])‬
‭print("2D Array created using numpy:")‬
‭print(array_2d)‬

‭Output‬
‭ 9 Write a program to convert a python list to a NumPy‬
Q
‭array.‬

‭ rogram‬
P
‭import numpy as np‬
‭list_2d = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]‬

‭array_2d = np.array(list_2d)‬

‭ rint("2D Python list:", list_2d)‬


p
‭print("Converted 2D NumPy array:\n", array_2d)‬

‭Output‬
‭ 10. Write a program to calculate mean, median and‬
Q
‭mode using Numpy for the following data‬
‭[5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4]‬

‭ rogram‬
P
‭import numpy as np‬
‭import statistics as stats‬
‭data = [5, 6, 1, 3, 4, 5, 6, 2, 7, 8, 6, 5, 4, 6, 5, 1, 2, 3, 4]‬
‭mean = np.mean(data)‬
‭median = np.median(data)‬
‭mode = stats.mode(data) print("Mean:", mean)‬
‭print("Median:", median) print("Mode:", mode)‬

‭Output‬
‭ 11. Write a program to display a scatter chart for the‬
Q
‭following points : (2,5), (9,10), (8,3), (5,7), (6,18).‬

‭ rogram‬
P
‭import matplotlib.pyplot as plt‬
‭x = [2, 9, 8, 5, 6]‬
‭y = [5, 10, 3, 7, 18]‬
‭plt.scatter(x, y, color='blue', marker='o')‬
‭plt.title("Scatter Plot for Given Points")‬
‭plt.xlabel("X values")‬
‭plt.ylabel("Y values")‬
‭plt.show()‬

‭Output‬
‭ 12 Write a program to represent the data on the‬
Q
‭ratings of mobile games on a 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‬

‭ rogram‬
P
‭import matplotlib.pyplot as plt‬
‭games = ['Pubg', 'FreeFire', 'MineCraft', 'GTA-V', 'Call of‬
‭Duty', 'FIFA 22']‬
‭ratings = [4.5, 4.8, 4.7, 4.6, 4.1, 4.3]‬
‭plt.bar(games, ratings, color='skyblue')‬
‭plt.title('Ratings of Mobile Games')‬
‭plt.xlabel('Games')‬
‭plt.ylabel('Ratings')‬
‭plt.show()‬

‭Output‬
‭ . Observe the given data for monthly sales of one of‬
3
‭the salesmen for 6 months. Plot them on the line chart.‬
‭Month January February March April May June‬
‭Sales 2500 2100 1700 3500 3000 3800‬

‭ rogram‬
P
‭import matplotlib.pyplot as‬
‭plt months = ['January', 'February', 'March', 'April', 'May',‬
‭'June']‬
‭sales = [2500, 2100, 1700, 3500, 3000, 3800]‬
‭plt.plot(months, sales, marker='o', color='b', linestyle='-',‬
‭linewidth=2, markersize=8)‬
‭plt.title('Sales Over 6 Months')‬
‭plt.xlabel('Month')‬
‭plt.ylabel('Sales')‬
‭plt.show()‬

‭Output‬
‭ 14. Write a program to read an image and display‬
Q
‭using Python.‬

‭ ython‬
P
‭import cv2‬
‭image = cv2.imread('d://download.jpg')‬
‭if image is None:‬
‭print("Error: Unable to load image")‬
‭else:‬
‭cv2.imshow('Image', image)‬
‭Output‬
‭ 15. Write a program to read an image and identify its‬
Q
‭shape using Python.‬

‭ rogram‬
P
‭import cv2‬
‭image = cv2.imread('d://ai.jfif')‬
‭if image is None:‬
‭print("Error: Unable to load image")‬
‭Else:‬
‭height, width, channels = image.shape‬
‭print(f"Height: {height} pixels")‬
‭print(f"Width: {width} pixels")‬
‭print(f"Channels: {channels} (3 for RGB, 1 for Grayscale)")‬

‭Output‬

You might also like