SHARE
TWEET

zodiac_schüler_test

DeaD_EyE Mar 17th, 2019 (edited) 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. from collections import Counter
  3. import datetime
  4. import textwrap
  5.  
  6.  
  7. try:
  8.     from fakeUserData import generator
  9. except ImportError:
  10.     print('Missing dependency')
  11.     print('pip install fakeUserData')
  12.     sys.exit(1)
  13.  
  14.  
  15. ZODIAC = {
  16.     12: ['sagittarius', 'capricorn', 22],
  17.     1:  ['capricorn', 'aquarius', 20],
  18.     2:  ['aquarius', 'pisces', 19],
  19.     3:  ['pisces', 'aries', 21],
  20.     4:  ['aries', 'taurus', 20],
  21.     5:  ['taurus', 'gemini', 21],
  22.     6:  ['gemini', 'cancer', 21],
  23.     7:  ['cancer', 'leo', 23],
  24.     8:  ['leo', 'virgo', 23],
  25.     9:  ['virgo', 'libra', 23],
  26.     10: ['libra', 'scorpio', 23],
  27.     11: ['scorpio', 'sagittarius', 22]
  28. }
  29.  
  30.  
  31. class Schüler:
  32.     def __init__(self, vorname, nachname, geburtstag):
  33.         self.vorname = vorname
  34.         self.nachname = nachname
  35.         self.geburtstag = geburtstag
  36.         self._zodiac = None
  37.    
  38.     @property
  39.     def zodiac(self):
  40.         if not self._zodiac:
  41.             before, after, day = ZODIAC[self.geburtstag.month]
  42.             self._zodiac = before.title() if self.geburtstag.day < day else after.title()
  43.         return self._zodiac
  44.    
  45.     def __repr__(self):
  46.         name = self.vorname + ' ' + self.nachname
  47.         return f'{self.__class__.__name__}(name="{name}", zodiac="{self.zodiac}")'
  48.  
  49.  
  50. def fake_schüler(n):
  51.     result = []
  52.     for _ in range(n):
  53.         vorname, nachname = generator.name().split()
  54.         day, month, year = generator.birthday()
  55.         geburtstag = datetime.date(year, month, day)
  56.         s = Schüler(vorname, nachname, geburtstag)
  57.         result.append(s)
  58.     return result
  59.  
  60.  
  61. def zähle_zodiac(schüler):
  62.     return Counter(s.zodiac for s in schüler)
  63.  
  64. def print_data(data):
  65.     text = textwrap.fill(str(data), initial_indent='# ', subsequent_indent='# ')
  66.     print(text)
  67.  
  68. schüler_liste = fake_schüler(10)
  69. zodiac_count = zähle_zodiac(schüler_liste)
  70.  
  71. print_data(schüler_liste)
  72. print()
  73. print_data(zodiac_count)
  74.  
  75.  
  76.  
  77. # output
  78. # [Schüler(name="Aleen Mccament", zodiac="Pisces"),
  79. # Schüler(name="Piper Mccart", zodiac="Libra"), Schüler(name="Ellena
  80. # Lapa", zodiac="Gemini"), Schüler(name="Aubrey Hillan",
  81. # zodiac="Capricorn"), Schüler(name="Lucia Heally",
  82. # zodiac="Capricorn"), Schüler(name="Fredric Ludgate",
  83. # zodiac="Pisces"), Schüler(name="Alexis Jaureguy", zodiac="Virgo"),
  84. # Schüler(name="Rico Norem", zodiac="Virgo"), Schüler(name="Olin
  85. # Saunder", zodiac="Virgo"), Schüler(name="Becki Nestico",
  86. # zodiac="Scorpio")]
  87.  
  88. # Counter({'Virgo': 3, 'Pisces': 2, 'Capricorn': 2, 'Libra': 1,
  89. # 'Gemini': 1, 'Scorpio': 1})
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top