samedi 8 mai 2021

Collections.deque() EOFError: EOF when reading a line

EOF error is occurring in this step method, val = input().split(' ') value error occurs when I remove the try block

from collections import deque
n = int(input())
d = deque()
for _ in range(n):
    try: 
    method, val = input().split(' ')
        if method == 'append':
            d.append(val)
        if method == 'appendleft':
            d.appendleft(val)
    except ValueError:
        a = input()
        if str(a) == 'pop':
            d.pop()
        else:
            d.popleft()
print(d)

Input given is :

 6
 append 1
 append 2
 append 3
 appendleft 4
 pop
 popleft

Aucun commentaire:

Enregistrer un commentaire