So, I am on a coding challenge site and I am trying to solve a problem. The expected output of the problem is this:-
['32']
['32', 'hello', '54']
Now, when I solved it on my system i.e. made a .py
file ran on terminal. It's output it same as shown above.
But on that site where I am doing this challenge, it's showing this output:-
[32]
[32, hello, 54]
I am banging my head on this. I can't seem to figure out what the problem is exactly.
I tried str()
, quoting it with ''
, but nothing seems to work on this site's coding console.
Any idea why is it happening?
For reference here is the problem description and my code.
Problem
- Your task is to maintain a list and perform two types of queries on it :
- Query '1' : It will be given as 1 x : Insert x into the list.
- Query '2' : It will be given as 2 : Print the contents of the list.
Code
def main():
n_of_queries = int(input("Queries count: "))
n_list=[]
for i in range(n_of_queries):
inp= input("Input: ")
typ = inp.split(' ')
if typ[0]=='1':
n_list.append(typ[1])
if typ[0]=='2':
print(n_list)
main()
Input
5
1 32
2
1 hello
1 54
2