0% found this document useful (0 votes)
5 views16 pages

Practicle File

The document contains a series of practical programming exercises that cover basic programming concepts such as checking voting eligibility based on age, determining if a number is even or odd, printing odd numbers, generating multiplication tables, calculating the sum of natural numbers, reversing a number, and manipulating lists in Python. Each exercise includes a question followed by a sample code solution. The exercises are designed to help learners practice fundamental programming skills.

Uploaded by

tanmay.gdgpsmt
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)
5 views16 pages

Practicle File

The document contains a series of practical programming exercises that cover basic programming concepts such as checking voting eligibility based on age, determining if a number is even or odd, printing odd numbers, generating multiplication tables, calculating the sum of natural numbers, reversing a number, and manipulating lists in Python. Each exercise includes a question followed by a sample code solution. The exercises are designed to help learners practice fundamental programming skills.

Uploaded by

tanmay.gdgpsmt
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/ 16

Practical – 3

Q- Write a program to check whether the person is eligible for vote


on the basis of age.
Ans- a = int(input(“enter your age:”))
If a>=18:
print(“You are eligible to vote!”)
else:
print(“Sorry, not eligible to vote!”)
Practical – 4
Q- Write a program to enter a number and find out entered number
is even or odd.
Ans- n = int(input(“Enter any number:”))
if n%2==0:
print(“The number is even”)
else:
print(“The number is odd”)
Practical – 5
Q- To input a number and print first N Odd numbers.
Ans. n = int(input(“Enter any number”))
for i in range(1,2*n+1,2):
print(i)
n = n+i
Practical -6
Q. Write a program to input a number and print table of a
number in the following format: (if N = 2)
2x1=2
2x2=4


2 x 10 = 20
Ans. n = int(input("Enter any number:"))
print ("TABLE OF ",n)
a=n*1
print (n,"*1=",a)
b=n*2
print (n,"*2=",b)
c=n*3
print (n,"*3=",c)
d=n*4
print (n,"*4=",d)
e=n*5
print (n,"*5=",e)
f=n*6
print (n,"*6=",f)
g=n*7
print (n,"*7=",g)
h=n*8
print (n,"*8=",h)
i=n*9
print (n,"*9=",i)
j=n*10
print (n,"*10=",j)
Practical – 7
Q- Write a program to print sum of N natural numbers.
Ans. n = int(input("Enter any number"))
s = n*(n+1)/ 2
print("The sum of",n,"natural numbers is",s)
Practical – 8
Q. Write a program to print reverse of a number.
Ans. n = int(input("Enter any number"))
rev = 0
while n>0:
r=n%10
n=n//10
rev=rev*10+r
print(rev)
Practical – 9
Q. Write a program to traverse a list.
Ans. cars = ["Mahindra","Toyota","Innova","BMW"]
for car in cars:
print(car)
Practical – 10 (i)
Q. If list L = [‘Sumit’, ’Lakshay’, ’Ronak’, ’Snehal’, ’Aditya’] :Add an element at
the end
Ans. L = ["Sumit", "Lakshay", "Ronak", "Snehal", "Aditya"]
L.append("Tanmay")
print(L)
(ii)
Q. If list L = [‘Sumit’, ’Lakshay’, ’Ronak’, ’Snehal’, ’Aditya’]: Add an
element at index 2
Ans. L = ["Sumit", "Lakshay", "Ronak", "Snehal", "Aditya"]
L.insert(2,"Tanmay")
print(L)
(iii)
Q. If list L = [‘Sumit’, ’Lakshay’, ’Ronak’, ’Snehal’, ’Aditya’]: delete an element
from the beginning.
Ans. L = ["Sumit", "Lakshay", "Ronak", "Snehal", "Aditya"]
L.pop(0)
print(L)
(iv)
Q. If list L = [‘Sumit’, ’Lakshay’, ’Ronak’, ’Snehal’, ’Aditya’]: delete the last
element
Ans. L = ["Sumit", "Lakshay", "Ronak", "Snehal", "Aditya"]
L.pop(4)
print(L)
(v)
Q. If list L = [‘Sumit’, ’Lakshay’, ’Ronak’, ’Snehal’, ’Aditya’]: delete
‘Ronak’ from the given list
Ans. L = ["Sumit", "Lakshay", "Ronak", "Snehal", "Aditya"]
L.remove('Ronak')
print(L)
(vi)
Q. If list L = [‘Sumit’, ’Lakshay’, ’Ronak’, ’Snehal’, ’Aditya’]: Sort the
list in ascending order.
Ans. L = ["Sumit", "Lakshay", "Ronak", "Snehal", "Aditya"]
L.sort()
print(L)
(vii)
Q. If list L = [‘Sumit’, ’Lakshay’, ’Ronak’, ’Snehal’, ’Aditya’]: Sort the list in
descending order.
Ans. L = ["Sumit", "Lakshay", "Ronak", "Snehal", "Aditya"]
L.sort(reverse=True)
print(L)
(viii)
Q. If list L = [‘Sumit’, ’Lakshay’, ’Ronak’, ’Snehal’, ’Aditya’]: Delete all
elements from the list
Ans. L = ["Sumit", "Lakshay", "Ronak", "Snehal", "Aditya"]
L.clear()
print(L)

You might also like