Ai Practicle
Ai Practicle
Page 1
QUESTION 1
Write a Python Script for basic calculator for performing addition/ subtraction/ multiplication/
division (by taking input from the user)?
#CODE
#OUTPUT
The Sum is 30
The difference is 10
Page 2
QUESTION 2
#CODE
#USE OF
#OUTPUT
RESULT OF 10//3 IS 3
Page 3
QUESTION 3
Write a Python Script to convert metres into kilometres and remaining metres.
#CODE
b=a//1000
c=a%1000
#OUTPUT
Page 4
QUESTION 4
Write the code to find the area or a circle. (take radius value as input)
#CODE
area=(22/7)*(r**2)
#OUTPUT
Page 5
QUESTION 5
a=10
b=7
a,b=b,a
print("THIS IS A",a)
print("THIS IS B",b)
#OUTPUT
THIS IS A 7
THIS IS B 10
Page 6
QUESTION 6
Write a Python Script to find the greatest/smallest number from the entered numbers?
#CODE
if a<b:
elif a>b:
else:
#OUTPUT
85 is greater than 45
Page 7
QUESTION 7
#CODE
a=int(input("ENTER A NUMBER"))
if a>0:
elif a<0:
elif a==0:
#OUTPUT
ENTER A NUMBER-9
Page 8
QUESTION 8
#CODE
#OUTPUT
Page 9
QUESTION 9
#CODE
if a>18:
elif a<18:
else:
#OUTPUT
Page 10
QUESTION 10
#CODE
a=int(input("ENTER A NUMBER"))
if a%2==0:
print(a,"IS EVEN")
else:
print(a,"IS ODD")
#OUTPUT
ENTER A NUMBER5
5 IS ODD
Page 11
QUESTION 11
#CODE
a=input("ENTER A ALPHABET")
if a in("a"or"A","e"or"E","i"or"I","o"or"O","u"or"U"):
print(a,"is vowel")
else:
print(a,"is consonant")
#OUTPUT
ENTER A ALPHABETa
a is vowel
Page 12
QUESTION 12
Write a Python Script to print from 1 to 10 or 10 to 1 (using for and while loop)?
#CODE
x=0
while(x!=10):
x=x+1
print(x)
#OUTPUT
10
Page 13
QUESTION 13
#CODE
for x in range(0,5):
print("DAV")
#OUTPUT
DAV
DAV
DAV
DAV
DAV
Page 14
QUESTION 14
Write a Python Script to find the sum of the first n natural numbers?
#CODE
n=int(input("ENTER A NO"))
add=(n*(n+1))/2
print(add)
#OUTPUT
ENTER A NO78
3081.0
Page 15
QUESTION 15
#CODE
a=int(input("ENTER NO"))
for x in range(0,11):
print(a,"X",x ,"=",x*a)
#OUTPUT
ENTER NO51
51 X 0 = 0
51 X 1 = 51
51 X 2 = 102
51 X 3 = 153
51 X 4 = 204
51 X 5 = 255
51 X 6 = 306
51 X 7 = 357
51 X 8 = 408
51 X 9 = 459
51 X 10 = 510
Page 16
QUESTION 16
Write the code to print even and odd series using while loop.
#CODE
a=int(input("Enter a number"))
for x in range(1,a+1):
print(x*2)
b=int(input("Enter a number"))
for z in range(1,b+1):
y=z*2
print(y+1)
#OUTPUT
Enter a number5
10
Enter a number5
11
Page 18
QUESTION 17
Write the code to print series 12 to 7 (reverse order) using while loop.
#CODE
x=7
while(x!=13):
print(x)
x=x+1
#OUTPUT
10
11
12
Page 19
QUESTION 18
#CODE
for x in range(1,i+1):
if i%x==0:
print(x)
#OUTPUT
FACTOR OF 45 is:
15
45
Page 20
QUESTION 19
#CODE
a=10
n1=0
n2=1
for i in range(a):
print(n1)
a=n1
n1=n2
n2=a+n2
#OUTPUT
13
21
34
Page 21
QUESTION 20
#CODE
res=1
print("FACTORIAL OF",x,"IS:")
for a in range(x,0,-1):
res=res*x
print(res)
#OUTPUT
ENTER A NUMBER4
FACTORAIL OF 4 IS 24
Page 22