fork download
  1. class BadSymbolException(Exception):
  2. pass
  3.  
  4. def getInt(n):
  5. res=[]
  6. c=0
  7. while(True):
  8. tmp=input()
  9. tmp=tmp.strip()
  10. acc=""
  11. l=len(tmp)
  12. for i in range(l):
  13. if (tmp[i]==' ') | (tmp[i]==','):
  14. if len(acc)>0:
  15. res+=[int(acc)]
  16. c+=1
  17. acc=""
  18. else:
  19. if (tmp[i]=='-'):
  20. if acc=="":
  21. acc="-"
  22. else:
  23. raise BadSymbolException("Минус внутри числа!")
  24. if (tmp[i]>='0') & (tmp[i]<='9'):
  25. acc+=tmp[i]
  26. if len(acc)>0:
  27. res+=[int(acc)]
  28. c+=1
  29. acc=""
  30. if (c>n):
  31. break
  32. return res[:n]
  33.  
  34. try:
  35. x=getInt(10)
  36. print(str(x))
  37. except BadSymbolException as e:
  38. print(e)
Success #stdin #stdout 0.02s 27632KB
stdin
1
2,
3,4,5,-6,,
7,8,9 -10 11 12
stdout
Минус внутри числа!