0% found this document useful (0 votes)
30 views2 pages

Prac QUESTION 1

The document contains code to perform various operations on lists based on user input such as printing even indexed elements, removing odd numbers, circularly shifting elements, doubling even elements, calculating sum of elements ending with 3, inserting and appending elements.

Uploaded by

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

Prac QUESTION 1

The document contains code to perform various operations on lists based on user input such as printing even indexed elements, removing odd numbers, circularly shifting elements, doubling even elements, calculating sum of elements ending with 3, inserting and appending elements.

Uploaded by

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

# PRACTICAL Question 1

choice=int(input('''1.Print elements at even index


2.Remove odd numbers from list
3.Right Circular shift (by n)on the elements of the list
4.Double every even element
5.Display even elements at odd locations from the list
6.Display the sum of elements ending with 3
7.Add element on a specific position given by user
8.Append element to the list
THE QUESTION YOU WANT TO RUN:'''))

if (choice==1):
l=eval(input("Enter the elements of the list:"))
print("The list is:",l)
a=len(l)
print("The number of elements are:",a)
for i in range(0,a):
if(i%2==0):
print("Indexes that have even elements are:",l[i])

if(choice==2):
l=eval(input("Enter the elements of the list:"))
print("The list is:",l)
a=len(l)
print("The number of elements are:",a)
for i in range(0,a):
if(i%2!=0):
l.remove(i)
print("The new list is:",l)

if(choice==3):
l=eval(input("Enter the list:"))
n=int(input("Enter the value of n:"))
for i in range(0,n):
k=l[-1]
for i in range(len(l)-1,0,-1):
l[i]=l[i-1]
l[0]=k
print("The new list is:",l)

if(choice==4):
l=eval(input("Enter the elements of the list:"))
print("The list is:",l)
a=len(l)
print("The number of elements are:",a)
for i in range(0,a):
if(l[i]%2==0):
l[i]=l[i]*2
print("The new list after doubling is:",l)

#COULD NOT DO PART 5

if(choice==6):
l=eval(input("Enter the list:"))
a=0
for i in l:
if i%10==3:
a=a+i
print("The sum of all the elements with 3 at the end is:",a)

if(choice==7):
l=eval(input("Enter the list:"))
n=int(input("Enter the index number where you want to add:"))
e=int(input("Enter the element you want to add:"))
l.insert(n,e)
print("The new list is:",l)

if(choice==8):
l=eval(input("Enter the list:"))
e=int(input("Enter the element you want to append:"))
l.append(e)
print("The new list is:",l)

You might also like