QuesAns Print Page – CSKC
Sign In

Search

siteicon
Q&A CBSE12A-2015-B02E #6359

Question:

Write a method in python to display the elements of list twice, if
it is a number and display the element terminated with ‘*’ if it is
not a number.
For example, if the content of list is as follows :
MyList=[‘RAMAN’,’21’,’YOGRAJ’, ‘3’, ‘TARA’]
The output should be
RAMAN*
2121
YOGRAJ*
33
TARA*

Answer:

def fun(L):
    for I in L:
        if I.isnumeric():
            print(2*I) # equivalently: print(I+I)
        else:
            print(I+'*')