AI Practical
AI Practical
AI Practical
Enter a number: 5
Cube of number is: 125
Q3 Write a program to input two integers and perform all arithmetc operations on them
============
Q6 Write a program to input two numbers and see if they are equal
============
Enter a number: 5
Number is odd
============
Enter a number: 10
Number is even
============
============
Q9 Write a program to print all items from a list containing some color names in it
In [12]: colorlist=["Red","Green","White","Black"]
for i in colorlist:
print(i)
Red
Green
White
Black
In [13]: markslist=[77,78,75,76,74]
print("List of marks:",markslist)
tmarks=0
for i in markslist:
tmarks=tmarks+i
print("Total marks is: ",tmarks)
In [15]: sum=0
for i in range(1,8):
sum=sum+i
print("Sum of first 7 natural numbers is: ",sum)
In [17]: i=1
while i<=5:
print("Square of",i,"is",i*i)
i+=1
Square of 1 is 1
Square of 2 is 4
Square of 3 is 9
Square of 4 is 16
Square of 5 is 25
Q14 Write a program to input a number and print the sum of numbers from 1 to num
Enter a number: 5
Sum of numbers from 1 to 5 is: 15
Q15 Program to calculate and print the sum of even and odd integers of the first n natural
numbers
Enter a number: 5
Factorial of 5 is: 120
Q17 Write a program to implement a simple calculator for two numbers. Offer a choice
through a menu
In [24]: def add(num1,num2):
return num1+num2
def sub(num1,num2):
return num1-num2
def mul(num1,num2):
return num1*num2
def div(num1,num2):
return num1/num2
while True:
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Exit")
if choice==5:
break
if choice==1:
print("Sum is: ",add(num1,num2))
print("\n============\n")
elif choice==2:
print("Difference is: ",sub(num1,num2))
print("\n============\n")
elif choice==3:
print("Product is: ",mul(num1,num2))
print("\n============\n")
elif choice==4:
print("Quotient is: ",div(num1,num2))
print("\n============\n")
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice: 0
Invalid choice
============
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice: 1
Enter first number: 5
Enter second number: 10
Sum is: 15
============
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice: 2
Enter first number: 10
Enter second number: 5
Difference is: 5
============
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice: 3
Enter first number: 5
Enter second number: 10
Product is: 50
============
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice: 4
Enter first number: 5
Enter second number: 10
Quotient is: 0.5
============
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice: 5
Q18 Write a program to allocate the grades of a student when grades are allocated in the
following manner:
Percentage Grade
Above 90% A
80% to 90% B
70% to 80% C
60% to 70% D
Below 60% E
============
============
============
============
Q19 Program to find the minimum element from a list along with its index in the list
In [27]: list=eval(input("Enter a list: "))
min=list[0]
index=0
for i in range(1,len(list)):
if list[i]<min:
min=list[i]
index=i
print("Minimum element is: ",min)
print("Index of minimum element is: ",index)
============
============
Q23 Menu Driven program to input a list and print sorted list, reverse of list , delete an
element using value and index.
============
1. Sort list
2. Reverse list
3. Delete an element using value
4. Delete an element using index
5. Exit
Enter your choice: 1
Sorted list is: [0, 1, 1, 1, 2, 3, 3, 4, 5, 5, 5, 5, 63, 101]
============
1. Sort list
2. Reverse list
3. Delete an element using value
4. Delete an element using index
5. Exit
Enter your choice: 2
Reversed list is: [3, 4, 5, 1, 3, 5, 2, 1, 1, 0, 5, 63, 101, 5]
============
1. Sort list
2. Reverse list
3. Delete an element using value
4. Delete an element using index
5. Exit
Enter your choice: 3
Enter a number: 0
List after deleting 0 is: [5, 101, 63, 5, 1, 1, 2, 5, 3, 1, 5, 4, 3]
============
1. Sort list
2. Reverse list
3. Delete an element using value
4. Delete an element using index
5. Exit
Enter your choice: 4
Enter an index: 5
List after deleting element at index 5 is: [5, 101, 63, 5, 0, 1, 2, 5,
3, 1, 5, 4, 3]
============
1. Sort list
2. Reverse list
3. Delete an element using value
4. Delete an element using index
5. Exit
Enter your choice: 5
Q24 Program to find mean, median, standard deviation and variance of array with values
[10,11,12,13,14,15]