Advertisement
KateWilson

Вывод четных/нечетных элементов списка

Jul 26th, 2019
1,128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. #В одну строку через пробел вводится массив из 10 целых чисел. Вывести его четные, затем нечетные элементы
  2.  
  3. #Вариант 1
  4. x = input()
  5. x = list(map(int, x.split()))
  6. chetnie = []
  7. nechetnie = []
  8.  
  9.  
  10. for i in range(10):
  11.    
  12.     if int(x[i]) % 2 == 0:
  13.         chetnie.append(x[i])
  14.     else:
  15.         nechetnie.append(x[i])
  16.        
  17.        
  18. print(' '.join(map(str, chetnie)))
  19. print(' '.join(map(str, nechetnie)))
  20.  
  21. #Вариант 2
  22. a = list(map(int,input().split()))
  23. odd = ' '
  24.  
  25. for char in a:
  26.     if char % 2 == 0:
  27.         print(char, end = ' ')
  28.     else:
  29.         odd += str(char) + ' '
  30.  
  31. print(odd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement