X-88

ganjilgenap.py

Nov 4th, 2021 (edited)
79
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #coded by: zephio-2021
  2. import os
  3. os.system('clear')
  4. x = 0
  5. ganjil = []
  6. genap = []
  7. inp = input("Masukkan Angka: ")
  8.  
  9. while (x < len(inp)):
  10.     z = int(inp[x])
  11.     if (z % 2) == 0:
  12.         genap.append(inp[x])
  13.         print(inp[x], '% 2 = ',  (z % 2), '[genap]')
  14.     else:
  15.         ganjil.append(inp[x])
  16.         print(inp[x], '% 2 = ',  (z % 2), '[ganjil]')
  17.     x += 1
  18.  
  19. print('-' * 25)
  20. print('Ganjil = ' + str(len(ganjil)) + '\n', *ganjil)
  21. print('Genap = '+ str(len(genap)) + '\n', *genap)
  22. """
  23. contoh 2 menggunakan for
  24.  
  25. for x, y in enumerate(inp):
  26.    z = int(y)
  27.    if z % 2 == 0:
  28.        print(y, '% 2 =',  (z % 2), '[genap]')
  29.    else:
  30.        print(y, '% 2 =',  (z % 2), '[ganjil]')
  31. """
RAW Paste Data Copied