You are on page 1of 5

LIST MANIPULATION

-Kritika Harlalka, XI-C1

1) Ask the user to enter a list containing numbers between 1


to 12. Then display all the entries in the list that are greater
than 10 with 10.
2) Ask the user to enter a list of strings. Create a new list that
consists of those strings with their first character removed.
3) Write a program to input if a number is present in the list or
not. If the number is present, print the position of the
number. Print an appropriate message if the number is not
present in the list.
4) Write a program that takes any two lists L and M of the same
size and adds their elements together to form a new list N
whose elements are sums of the corresponding elements in
L and M. For instance, if L=[3,1,4] and M=[1,5,9] then N
should equal to [4,6,13].
5) Write a program to read two lists num and denim which
contain the numerators and denominators of the same
fractions at the respective indexes. Then display the
smallest fraction along its index.
6) Write a program to move all duplicate values in a list to the
end of the list.
7) From a balance sheet of a company (choose any from your
Accountancy book) and create lists for assets, liabilities and
equity. Then write a program to check if the accounting
equation is balanced or not. The program should also
calculate Return on Total Assets as
EBIT(Earning Before Interest and Taxes)/ Total Net Assets
and Debit /Equity Ratio as Total Liabilities/Assets-Liabilities.

ANSWERS:
1) l1= eval(input("Enter numbers between 1 to 12: "))
for i in range(len(l1)):
if l1[i]>10:
l1[i]=10
print(l1)

2) l1= eval(input("Enter a list of srtings: "))


l2=[]
for i in range(len(l1)):
l2.append(l1[i][1:])
print("List after removing first charachters: ",l2)

3) l1=[]
l1= eval(input("Enter the list: "))
n= int(input("Enter the number which is to be checked: "))
if n in l1:
print(l1.index(n)+1)
else:
print("The number is not found")
4) print("Enter two lists of the same size")
L= eval(input("Enter first list(L): "))
M = eval(input("Enter second list(M): "))
N = []

for i in range(len(L)):
N.append(L[i] + M[i])

print("List N: ",N)

5) num= eval(input("Enter the numerator's list: "))


denum= eval(input("Enter denominator's list: "))
small= num[0]/denum[0]
small_index=0
for i in range(1,len(num)):
fraction= num[i]/denum[i]
if fraction <small:
small= fraction
smallind=i
print("Smallest fraction= ",num[smallind],"/",
denum[smallind])
print("Index of smallest fraction: ",smallind)

6) l1= eval(input("Enter the list: "))


dedup=[]
dup=[]
for i in l1:
if i in dedup:
dup.append(i)
else:
dedup.append(i)

l1 = dedup + dup

print("Modified List:",l1)

7) assets = eval(input("Enter assets list: "))


liabilitie = eval(input("Enter liabilitie list: "))
equity = eval(input("Enter equity list: "))

for i in range(len(equity)):
print("for item number ",i)
if assets[i]==liabilitie[i]+equity[i]:
print("Balanced")
else:
print("Not Balanced")
print("Debt/Equity ratio= ",sum(liabilitie)/(
assets[i]-liabilitie[i]))

You might also like