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#
>>>
414141
DRONE#
GIRIRAJ#
131313
ZARA#
>>>
Enter a list :-["PathWalla","123456"]
PathWalla#
123456123456123456
>>>
After ZARA their will also#
ReplyDeleteOk, I have updated it.
DeleteIt is "DROND" not 'DRONE' in example
ReplyDeleteOk, I have corrected it.
Deletegood job gro
DeleteThank you
ReplyDeleteWelcome 😊😊
Deletelst = eval(input("Enter a list :-"))
ReplyDeletefor i in lst :
if isinstance(i, int) :
print(str(i)*3)
elif isinstance(i, str) :
print(i+"#")
indentation is not working
DeleteYour program is not giving desired output.
Deletewrong code not working with alphabetical value
ReplyDeleteYou are wrong, answer is correct please check it in your python software.
Deletelist1 = []
ReplyDeletelist1 = 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+"#")
or simple code will be:
Deletelist1 = eval(input("Please enter a list: "))
for i in list1 :
i = str(i)
if i.isdigit() :
print(i*3)
elif i.isalpha() :
print(i+"#")
: )
DeleteSuch a great website and you reply to comments too. May God Bless You <3
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )