Q. Write a method in python to display the elements of list thrice 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:
List = ['41', 'DRONE', 'GIRIRAJ', '13', 'ZARA']

The output should be

414141
DRONE#
GIRIRAJ#
131313
ZARA#

Answer :-

lst = eval(input("Enter a list :-"))
for i in lst :
    if i.isdigit() :
        print(i*3)
    elif i.isalpha() :
        print(i+"#")

Output :-

Enter a list :-['41', 'DRONE', 'GIRIRAJ', '13', 'ZARA']
414141
DRONE#
GIRIRAJ#
131313
ZARA#

>>> 

Enter a list :-["PathWalla","123456"]
PathWalla#
123456123456123456

>>> 


16 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. After ZARA their will also#

    ReplyDelete
  2. It is "DROND" not 'DRONE' in example

    ReplyDelete
  3. lst = eval(input("Enter a list :-"))
    for i in lst :
    if isinstance(i, int) :
    print(str(i)*3)
    elif isinstance(i, str) :
    print(i+"#")

    ReplyDelete
  4. wrong code not working with alphabetical value

    ReplyDelete
    Replies
    1. You are wrong, answer is correct please check it in your python software.

      Delete
  5. list1 = []

    list1 = input('Enter a string: ')
    list1 = list1.split()

    n = int(input("Enter number of elements: "))

    for i in range(0,n):
    ele = int(input())
    list1.append(ele)

    print("Here is the list made by ya",list1)

    print("now there is a function that will make an integer thrice but a string will end with # sign")

    for i in list1 :
    i = str(i)
    if i.isdigit() :
    print(i*3)
    elif i.isalpha() :
    print(i+"#")

    ReplyDelete
    Replies
    1. or simple code will be:

      list1 = eval(input("Please enter a list: "))
      for i in list1 :
      i = str(i)
      if i.isdigit() :
      print(i*3)
      elif i.isalpha() :
      print(i+"#")

      Delete
    2. Such a great website and you reply to comments too. May God Bless You <3

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post