fork download
  1. n = int(input())
  2.  
  3. namespaces = {'global' : ''}
  4. variables = {}
  5.  
  6.  
  7. def get_namespace(ns, v):
  8. if ns == '' or ns not in namespaces.keys():
  9. return 'None'
  10. if ns not in variables.keys():
  11. return get_namespace(namespaces[ns], v)
  12. if v in variables[ns]:
  13. return ns
  14. return get_namespace(namespaces[ns], v)
  15.  
  16.  
  17. for i in range(n):
  18. a, b, c = map(str, input().split())
  19. if a == 'create':
  20. namespaces[b] = c
  21. elif a == 'add':
  22. if b not in variables.keys():
  23. variables[b] = []
  24. variables[b].append(c)
  25. else:
  26. print(get_namespace(b, c))
  27.  
Runtime error #stdin #stdout #stderr 0.15s 23176KB
stdin
2
create bar2 global
get bar2 a
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 26, in <module>
  File "./prog.py", line 12, in get_namespace
KeyError: 'bar2'