AI & ML Practical 1
AI & ML Practical 1
CODE :-
a=3
print(a)
str = 'Hello World!'
var2 = 0
if var2:
print ("2 - Got a true expression value")
print (var2)
print ("Good bye!")
if amount<1000:
discount=amount*0.05
print ("Discount",discount)
else:
discount=amount*0.10
print ("Discount",discount)
num=int(input("enter number"))
if num%2==0:
if num%3==0:
print ("Divisible by 3 and 2")
else:
print ("divisible by 2 not divisible by 3")
else:
if num%3==0:
print ("divisible by 3 not divisible by 2")
else:
print ("not Divisible by 2 not divisible by 3")
count = 0
while count < 9:
print ('The count is:', count)
count = count + 1
numbers=[11,33,55,39,55,75,37,21,23,41,13]
string = "apple,orange,banana"
fruits = string.split(',')
print("Fruits:", fruits)
import numpy as np
# Create a 1D array
arr_1d = np.array([1, 2, 3])
# Create a 2D array
arr_2d = np.array([[1, 2, 3], [4, 5, 6]])
print(arr_1d)
import numpy as np
# Element-wise addition
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
result = arr1 + arr2
# Element-wise multiplication
result_multiply = arr1 * arr2
# Matrix multiplication
matrix1 = np.array([[1, 2], [3, 4]])
matrix2 = np.array([[5, 6], [7, 8]])
result_matrix_multiply = np.dot(matrix1, matrix2)
import numpy as np
# Indexing
arr = np.array([1, 2, 3, 4, 5])
print(arr[2]) # Output: 3
# Slicing
arr_slice = arr[1:4] # Slice elements from index 1 to 3
import numpy as np
# Shape of an array
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr.shape) # Output: (2, 3)
# Reshape an array
reshaped_arr = arr.reshape(3, 2)
import numpy as np
# Sample data
x = [10, 20, 30, 40, 5]
y = [10, 40, 16, 18, 10]
#scatter plot
# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# bar chart
# Sample data
categories = ['Category A', 'Category B', 'Category C', 'Category D']
values = [30, 50, 20, 40]
# Create a histogram
plt.hist(data, bins=30, color='green', edgecolor='black')
OUTPUT :-