surya_adi

himpunan.py

Dec 5th, 2020
666
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!usr/bin/env python3
  2.  
  3. """
  4. himpunan
  5. """
  6.  
  7. from random import randint
  8.  
  9. def num():
  10.     """random number"""
  11.     return randint(-50, 50)
  12.  
  13. himp = [num() for x in range(6)]
  14.  
  15. kosong = [x for x in himp if x == 0]
  16. negatif = [x for x in himp if x < 0]
  17. positif = [x for x in himp if x > 0]
  18.  
  19. print("kosong = %s, %g%s dari himp" % (kosong, len(kosong)/len(himp)*100, "%"))
  20. print("negatif = %s, %g%s dari himp" % (negatif, len(negatif)/len(himp)*100, "%"))
  21. print("positif = %s, %g%s dari himp" % (positif, len(positif)/len(himp)*100, "%"))
RAW Paste Data