0% found this document useful (0 votes)
28 views23 pages

Ai Practicle

The document contains 20 questions related to Python programming. The questions cover topics like basic calculator operations, operators like exponents, floor division and modulo, converting units like metres to kilometres, finding area of a circle, swapping variable values, determining greatest of numbers, checking positive/negative/even/odd numbers, checking vowel/consonant, printing patterns using loops, calculating sum of first n natural numbers, printing tables, finding factors, printing Fibonacci series, and calculating factorials. Sample code and outputs are provided for each question.

Uploaded by

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

Ai Practicle

The document contains 20 questions related to Python programming. The questions cover topics like basic calculator operations, operators like exponents, floor division and modulo, converting units like metres to kilometres, finding area of a circle, swapping variable values, determining greatest of numbers, checking positive/negative/even/odd numbers, checking vowel/consonant, printing patterns using loops, calculating sum of first n natural numbers, printing tables, finding factors, printing Fibonacci series, and calculating factorials. Sample code and outputs are provided for each question.

Uploaded by

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

Sr.

Contents Page Remarks


No. Number
1 Write a Python Script for basic calculator for
performing addition/ subtraction/ multiplication/
division (by taking input from the user)?
2 Write a Program to use the following operators.
**, //, %
3 Write a Python Script to convert metres into
kilometres and remaining metres.
4 Write the code to find the area or a circle. (take radius
value as input)
5 Write a program to swap the values of two variables.
6 Write a Python Script to find the greatest/smallest
number from the entered numbers?
7 Write a Python Script to find the number is positive or
negative?
8 Write the code to find the greatest of three numbers.
9 Write a Python Script to find if the person is eligible to
vote or not?
10 Write the code to check the given number is even or
odd.
11 Write a program to accept a alphabet and check
whether it is vowel or not.
12 Write a Python Script to print from 1 to 10 or 10 to 1
(using for and while loop)?
13 Write a program to print "DAV" 5 times using for
loop.
14 Write a Python Script to find the sum of the first n
natural numbers?
15 Write a Python Script to print the table of an entered
number?
16 Write the code to print even and odd series using while
loop.
17 Write the code to print series 12 to 7 (reverse order)
using while loop.
18 Write a Python Script to find the factors of the entered
number?
19 Write a Python Script to print Fibonacci series up to
ten values?
20 Write a Python Script to find the factorial of a
number?

Page 1
QUESTION 1

Write a Python Script for basic calculator for performing addition/ subtraction/ multiplication/
division (by taking input from the user)?

#CODE

a= int (intput ("Enter the first number?"))

b = int ( input. ("Enter the second numbers"))

print ("The sum is ", a+b)

print (" The difference is", a-b)

print ("The division result is", a /b)

print ("The multiplication result is" ,a* b).

#OUTPUT

Enter the first number 20

Enter the Second number 10

The Sum is 30

The difference is 10

The division result is 2

The multiplication result is 200

Page 2
QUESTION 2

Write a Program to use the following operators.


**, //, %

#CODE

#USE OF

#1.) **--FOR GIVING POWER TO A NUMBER

print("RESULT OF 9x9x9 IS ",9**3)

#2.) //---FIND THE QUOTIENT WITHOUT DECIMAL

print("RESULT OF 10//3 IS",10//3)

#3.) %---TO FIND THE REMAINDER

print("THE REMAINDER AFTER DIVIDING 3 WITH 10 IS:",10%3)

#OUTPUT

RESULT OF 9x9x9 IS 729

RESULT OF 10//3 IS 3

THE REMAINDER AFTER DIVIDING 3 WITH 10 IS: 1

Page 3
QUESTION 3

Write a Python Script to convert metres into kilometres and remaining metres.
#CODE

a=int(input("ENTER THE DISTANCE IN M"))

b=a//1000

c=a%1000

print(a,"m equals to",b,"km and",c,"m")

#OUTPUT

ENTER THE DISTANCE IN M75552

75552 m equals to 75 km and 552 m

Page 4
QUESTION 4

Write the code to find the area or a circle. (take radius value as input)
#CODE

r=int(input("ENTER THE RADIUS OF A CIRCLE"))

area=(22/7)*(r**2)

print("AREA OF CIRCLE IS:",area,"sq.units")

#OUTPUT

ENTER THE RADIUS OF A CIRCLE7

AREA OF CIRCLE IS: 154.0 sq.units

Page 5
QUESTION 5

Write a program to swap the values of two variables.


#CODE

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

a=int(input("ENTER FIRST NUMBER"))

b=int(input("ENTER SECOND NUMBER"))

if a<b:

print(b,"is greater than",a)

elif a>b:

print(a,"is greater than",b)

else:

print(a,"is equal to",b)

#OUTPUT

ENTER FIRST NUMBER45

ENTER SECOND NUMBER85

85 is greater than 45

Page 7
QUESTION 7

Write a Python Script to find the number is positive or negative?

#CODE

a=int(input("ENTER A NUMBER"))

if a>0:

print("YOUR NUMBER IS POSITIVE")

elif a<0:

print("YOUR NUMBER IS NEGATIVE")

elif a==0:

print("YOUR NUMBER IS EQUAL TO ZERO")

#OUTPUT

ENTER A NUMBER-9

YOUR NUMBER IS NEGATIVE

Page 8
QUESTION 8

Write the code to find the greatest of three numbers.

#CODE

a=int(input("ENTER FIRST NUMBER"))

b=int(input("ENTER SECOND NUMBER"))

c=int(input("ENTER THIRD NUMBER"))

if a<b and c<b:

print(b,"is greater than",a,"and",c)

elif b<a and c<a:

print(a,"is greater than",b,"and",c)

elif b<c and a<c:

print(c,"is greater than",b,"and",a)

#OUTPUT

ENTER FIRST NUMBER4

ENTER SECOND NUMBER5

ENTER THIRD NUMBER6

6 is greater than 5 and 4

Page 9
QUESTION 9

Write a Python Script to find if the person is eligible to vote or not?

#CODE

a=int(input("ENTER YOUR AGE"))

if a>18:

print("YOU CAN VOTE")

elif a<18:

print("YOU CANNOT VOTE")

else:

print("YOU CAN VOTE NEXT YEAR")

#OUTPUT

ENTER YOUR AGE4

YOU CANNOT VOTE

Page 10
QUESTION 10

Write the code to check the given number is even or odd.

#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

Write a program to accept a alphabet and check whether it is vowel or not.

#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

Write a program to print "DAV" 5 times using for loop.

#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

Write a Python Script to print the table of an entered number?

#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"))

print(a,"even numbers are")

for x in range(1,a+1):

print(x*2)

b=int(input("Enter a number"))

print(b,"odd numbers are")

for z in range(1,b+1):

y=z*2

print(y+1)

#OUTPUT

Enter a number5

5 even numbers are

10

Enter a number5

5 odd numbers are


Page 17
3

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

Write a Python Script to find the factors of the entered number?

#CODE

i=int(input("ENTER YOUR NUMBER"))

print("FACTOR OF", i,"is:")

for x in range(1,i+1):

if i%x==0:

print(x)

#OUTPUT

ENTER YOUR NUMBER45

FACTOR OF 45 is:

15

45

Page 20
QUESTION 19

Write a Python Script to print Fibonacci series up to ten values?

#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

Write a Python Script to find the factorial of a number?

#CODE

x=int(input("ENTER THE NUMBER"))

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

You might also like