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

Ai Practical

Uploaded by

ipsabhaytiwari12
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 views6 pages

Ai Practical

Uploaded by

ipsabhaytiwari12
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/ 6

Prepare an AI practical file with these Python, Data Science, and

Computer Vision programs for your practicals and viva.

1. Write a Python program to print "Hello, World!" to the console.

2. Write a program to add two numbers.

3. Write a Python program to find the square of a number.

4. Take input from the user and display it.

5. Write a program to check if a number is even or odd.

6. Create a list of 5 numbers and print it.

7. Write a program to find the sum of all numbers in a list.

8. Write a Python program to reverse a string.

9. Write a program to check if a given number is divisible by 5.

10. Create a program to calculate the area of a rectangle (length × breadth).

11. Create a NumPy array with 3 numbers and print it.

12. Create a pandas DataFrame with one column and display it.

13. Write a program to add two NumPy arrays element-wise.

14. Write a program to calculate the sum of all values in a pandas DataFrame column.

15. Write a program to find the maximum value in a NumPy array.


Solutions:

1. Print "Hello, World!"

print("Hello, World!")

Output:

Hello, World!

2. Add two numbers

a = int(input("Enter the first number: ")) # Enter 5

b = int(input("Enter the second number: ")) # Enter 3

print("Sum:", a + b)

Input:

Enter the first number: 5

Enter the second number: 3

Output:

Sum: 8

3. Find the square of a number

num = int(input("Enter a number: ")) # Enter 4

print("Square:", num ** 2)

Input:

Enter a number: 4

Output:

Square: 16
4. Take input from the user and display it

user_input = input("Enter something: ") # Enter "Python is fun!"

print("You entered:", user_input)

Input:

Enter something: Python is fun!

Output:

You entered: Python is fun!

5. Check if a number is even or odd

num = int(input("Enter a number: ")) # Enter 7

if num % 2 == 0:

print("Even")

else:

print("Odd")

Input:

Enter a number: 7

Output:

Odd

6. Create a list of 5 numbers and print it

numbers = [10, 20, 30, 40, 50]

print("List:", numbers)

Output:

List: [10, 20, 30, 40, 50]


7. Find the sum of all numbers in a list

numbers = [1, 2, 3, 4, 5]

print("Sum:", sum(numbers))

Output:

Sum: 15

8. Reverse a string

string = input("Enter a string: ") # Enter "hello"

print("Reversed string:", string[::-1])

Input:

Enter a string: hello

Output:

Reversed string: olleh

9. Check if a number is divisible by 5

num = int(input("Enter a number: ")) # Enter 25

if num % 5 == 0:

print("Divisible by 5")

else:

print("Not divisible by 5")

Input:

Enter a number: 25

Output:

Divisible by 5
10. Calculate the area of a rectangle

length = float(input("Enter the length: ")) # Enter 5

breadth = float(input("Enter the breadth: ")) # Enter 3

print("Area:", length * breadth)

Input:

Enter the length: 5

Enter the breadth: 3

Output:

Area: 15.0

11. Create a NumPy array with 3 numbers and print it

import numpy as np

arr = np.array([1, 2, 3])

print("NumPy Array:", arr)

Output:

NumPy Array: [1 2 3]

12. Create a pandas DataFrame with one column and display it

import pandas as pd

data = pd.DataFrame({'Numbers': [10, 20, 30]})

print(data)

Output:

Numbers

0 10

1 20

2 30
13. Add two NumPy arrays element-wise

import numpy as np

arr1 = np.array([1, 2, 3])

arr2 = np.array([4, 5, 6])

result = arr1 + arr2

print("Sum of arrays:", result)

Output:

Sum of arrays: [5 7 9]

14. Calculate the sum of all values in a pandas DataFrame column

import pandas as pd

data = pd.DataFrame({'Numbers': [10, 20, 30]})

print("Sum of column:", data['Numbers'].sum())

Output:

Sum of column: 60

15. Find the maximum value in a NumPy array

import numpy as np

arr = np.array([10, 20, 5, 40])

print("Maximum value:", arr.max())

Output:

Maximum value: 40

You might also like