[go: up one dir, main page]

0% found this document useful (0 votes)
26 views10 pages

AI & ML Practical 1

Uploaded by

Janu Cool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views10 pages

AI & ML Practical 1

Uploaded by

Janu Cool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

AI & ML

NAME: Rudrarajsinh Padheriya


Practical: 1
Roll no. 23BCL122(Civil(M))

CODE :-

a=3
print(a)
str = 'Hello World!'

print (str) # Prints complete string


print (str[0]) # Prints first character of the string
print (str[2:5]) # Prints characters starting from 3rd to
str = 'Hello World!'

print (str) # Prints complete string


print (str[0]) # Prints first character of the string
print (str[2:9]) # Prints characters starting from 3rd to
str = 'purvang prajapti'

print (str) # Prints complete string


print (str[0]) # Prints first character of the string
print (str[2:5])
# Prints characters starting from 3rd to
list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john']

print (list) # Prints complete list


print (list[0]) # Prints first element of the list
print (list[1:3]) # Prints elements starting from 2nd till 3rd
print (list[2:]) # Prints elements starting from 3rd element
print (tinylist * 2) # Prints list two times
print (list + tinylist) # Prints concatenated lists
tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )
tinytuple = (123, 'john')

print (tuple) # Prints complete tuple


print (tuple[0]) # Prints first element of the tuple
print (tuple[1:3]) # Prints elements starting from 2nd till 3rd
print (tuple[2:]) # Prints elements starting from 3rdelment
print (tinytuple * 2) # Prints tuple two times
print (tuple + tinytuple) # Prints concatenated tup
a=[
[1,2,3],
[4,5,6]
]
var1 = 100
if var1:
print ("1 - Got a true expression value")
print (var1)

var2 = 0
if var2:
print ("2 - Got a true expression value")
print (var2)
print ("Good bye!")

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

if amount<1000:
discount=amount*0.05
print ("Discount",discount)
else:
discount=amount*0.10
print ("Discount",discount)

print ("Net payable:",amount-discount)

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


if amount<1000:
discount=amount*0.05
print ("Discount",discount)
elif amount<5000:
discount=amount*0.10
print ("Discount",discount)
else:
discount=amount*0.15
print ("Discount",discount)

print ("Net payable:",amount-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

print ("Good bye!")

for letter in 'Python': # traversal of a string sequence


print ('Current Letter :', letter)

fruits = ['banana', 'apple', 'mango']


for fruit in fruits: # traversal of List sequence
print ('Current fruit :', fruit)

print ("Good bye!")

fruits = ['banana', 'apple', 'mango']


for index in range(len(fruits)):
print ('Current fruit :', fruits[index])

print ("Good bye!")

for letter in 'Python':


if letter == 'h':
break
print ('Current Letter :', letter)

for letter in 'Python':


if letter == 'h':
continue
print ('Current Letter :', letter)

numbers=[11,33,55,39,55,75,37,21,23,41,13]

for num in numbers:


if num%2==0:
print ('the list contains an even number')
break
else:
print ('the list does not contain even number')

list = ['physics', 'chemistry', 1997, 2000]


print (list)
del list[2]
print ("After deleting value at index 2 : ", list)

# Function definition is here


def changeme( mylist ):
"This changes a passed list into this function"
print ("Values inside the function before change: ", mylist)
mylist[2]=50
print ("Values inside the function after change: ", mylist)
return

# Now you can call changeme function


mylist = [10,20,30]
changeme( mylist )
print ("Values outside the function: ", mylist)

# Function definition is here


def changeme( mylist ):
"This changes a passed list into this function"
mylist = [1,2,3,4] # This would assign new
reference in mylist
print ("Values inside the function: ", mylist)
return

# Now you can call changeme function


mylist = [10,20,30]
changeme( mylist )
print ("Values outside the function: ", mylist)

total = 0 # This is a global variable.


# Function definition is here
def sum( arg1, arg2 ):
# Add both the parameters and return them."
total = arg1 + arg2; # Here total is local variable.
print ("Inside the function local total : ", total)
return

# Now you can call sum function


sum( 10, 20 )
print ("Outside the function global total : ", total )

total = 0 # This is global variable.


# Function definition is here
def sum( arg1, arg2 ):
# Add both the parameters and return them."
global total
total = arg1 + arg2;
print ("Inside the function local total : ", total)
return

# Now you can call sum function


sum( 10, 20 )
print ("Outside the function global total : ", total )

string = "Hello, World!"


length = len(string)
print("Length of the string:", length)

string = "Hello, World!"


lower_case = string.lower()
upper_case = string.upper()
print("Lowercase:", lower_case)
print("Uppercase:", upper_case)

string = " Hello, World! "


stripped_string = string.strip()
print("Stripped string:", stripped_string)

string = "Hello, World!"


new_string = string.replace("World", "Python code code")
print("Modified string:", new_string)

string = "apple,orange,banana"
fruits = string.split(',')
print("Fruits:", fruits)

fruits = ["apple", "orange", "banana"]


joined_string = ', '.join(fruits)
print("Joined string:", joined_string)

string = "Hello, World!"


index1 = string.find("World")
index2 = string.index("World")
print("Index using find():", index1)
print("Index using index():", index2)
string = "Hello, World!"
starts_with_hello = string.startswith("Hello")
ends_with_world = string.endswith("World")
print("Starts with 'Hello':", starts_with_hello)
print("Ends with 'World':", ends_with_world)

text = "hello, world!"


capitalized_text = text.capitalize()
print("Original text:", text)
print("Capitalized text:", capitalized_text)

text = "hello, world!"


title_text = text.title()
print("Original text:", text)
print("Titlecased text:", title_text)

text = "Hello, World!"


upper_text = text.upper()
lower_text = text.lower()
print("Original text:", text)
print("Uppercased text:", upper_text)
print("Lowercased text:", lower_text)

text = "hello world"


title_case = text.title()
print("Title case:", title_case)

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]])

# Create an array of zeros


zeros_arr = np.zeros((2, 3))

# Create an array of ones


ones_arr = np.ones((3, 2))

# Create an array with a range of values


range_arr = np.arange(0, 10, 2) # Start, Stop, Step

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

# Sum, mean, and standard deviation


arr = np.array([1, 2, 3, 4, 5])
sum_arr = np.sum(arr)
mean_arr = np.mean(arr)
std_arr = np.std(arr)

# basic line plot

import matplotlib.pyplot as plt

# Sample data
x = [10, 20, 30, 40, 5]
y = [10, 40, 16, 18, 10]

# Create a simple line plot


plt.plot(x, y)

# Add labels and title


plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Simple Line Plot')

# Display the plot


plt.show()

#scatter plot

import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

# Create a scatter plot


plt.scatter(x, y, color='blue', marker='o')

# Add labels and title


plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot')

# Display the plot


plt.show()

# bar chart

import matplotlib.pyplot as plt

# Sample data
categories = ['Category A', 'Category B', 'Category C', 'Category D']
values = [30, 50, 20, 40]

# Create a bar chart


plt.bar(categories, values, color='red')

# Add labels and title


plt.xlabel('Categories')
plt.ylabel('Values')
plt.title('Bar Chart')

# Display the plot


plt.show()
#histogram

import matplotlib.pyplot as plt


import numpy as np

# Generate random data for the histogram


data = np.random.randn(1000)

# Create a histogram
plt.hist(data, bins=30, color='green', edgecolor='black')

# Add labels and title


plt.xlabel('Values')
plt.ylabel('Frequency')
plt.title('Histogram')

# Display the plot


plt.show()

OUTPUT :-

You might also like