AI practical File
AI practical File
(Please copy all these programs along with the output in the Practical file
NOTEBOOK)
Q. 1 Assign three variables with the same value and print it.
X=Y=Z=10 print(X,Y,Z)
OUTPUT:
10 10 10
OUTPUT:
Enter temperature in Fahrenheit:100
Temperature in Celsius: 37.77777777777778
Q.3 Write a program to calculate simple interest. Accept Principle
amount, rate of interest and time from user. Display Simple Interest.
OUTPUT:
OUTPUT:
Enter the first number:10
Enter the second number:7
The larger number is: 10
Q.5 Write a program to print area of triangle, take base and height as
user input.
b=float(input("Enter base of a triangle:"))
h=float(input("Enter height of a triangle:"))
area=(b * h)/2
print("Area of triangle:", area)
OUTPUT:
Q.6 Write a program to accept age of a person and check his eligibility
of voting.
age= int(input("Enter your age:"))
if age>=18 :
print("You are eligible for voting.")
else:
print("You are not eligible for voting.")
OUTPUT:
OUTPUT:
OUTPUT:
Enter a number:7
The sum of 7 natural numbers is: 28
Q.9 Given list as L=['a','b','c','d','e']. Take input of index from the user
and remove that element using pop( ) function
L=['a','b','c','d','e']
print("Original List: ",L)
i=int(input("Enter the index of the element to be
removed: "))
L.pop(i)
print("List after removing element",L) Original
List: ['a', 'b', 'c', 'd', 'e']
OUTPUT:
OUTPUT:
L = ['a','e,','i','o','u'] print(L)
OUTPUT:
OUTPUT:
OUTPUT:
cir =2*pi*r
OUTPUT:
Enter a number: 3
Cube of a given number is : 27
Q. 18 Write a program to accept a number from the user and display if
it is positive, negative or zero.
n=float(input("Enter a number:")) if
n>0:
print("The number is positive number") if
n<0:
print("The number is negative number") if
n==0:
print("The number is Zero")
OUTPUT:
Enter a number:34
The number is positive number
Q19. Write a program to accept a string from the user and print it in the
reverse order.
s=input("Enter a string: ")
print(s[:: -1])
OUTPUT:
Enter a string: Good Morning
gninroM dooG
Q20. Write a program to accept a string from the user and print its first
and last characters
s=input("Enter a string: ") print("The
first character is :", s[0]) print("The
last character is :", s[-1])
OUTPUT:
Enter a string: Python
The first character is : P
The last character is : n