Advertisement
clevernessisamyth

Exam Python 2015 & 2019

Mar 10th, 2021 (edited)
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.91 KB | None | 0 0
  1. ### EX1
  2.  
  3. # 2015
  4. class Vecteur2D:
  5.     def __init__(self, x = 0, y = 0):
  6.         self.x = x
  7.         self.y = y
  8.    
  9.     def affiche(self):
  10.         print(self.x, ',', self.y)
  11.  
  12.     def __add__(self, v):
  13.         return Vecteur2D(self.x + v.x, self.y + v.y)
  14.  
  15. v1 = Vecteur2D(2, 3)
  16. v2 = Vecteur2D(3, 4)
  17. v3 = v1 + v2
  18. v3.affiche()
  19.  
  20. # 2019
  21. class Verbe:
  22.     def __init__(self, verbe):
  23.         self.verbe = verbe.lower.strip()
  24.  
  25.     def type(self):
  26.         groupe = "troisième"
  27.         if self.verbe[-2:] == 'er':
  28.             groupe = 'premier'
  29.         if self.verbe[-2:] == 'ir':
  30.             groupe = 'deuxième'
  31.         return(groupe)
  32.  
  33.     def affiche(self):
  34.         print(self.verbe)
  35.  
  36.     def conjuguer(self, temps):
  37.         ppgp = {
  38.             'Je': 'e',
  39.             'Tu': 'es',
  40.             'Il': 'e',
  41.             'Nous': 'ons',
  42.             'Vous': 'ez',
  43.             'Ils': 'ent'
  44.         }
  45.  
  46.         if temps == 'présent' and self.type() == 'premier':
  47.             pronouns = ppgp
  48.  
  49.         for p in pronouns:
  50.             pronoun = p + ' '
  51.             if(p == 'Je' and self.verbe[0] in ('e', 'é', 'a', 'o', 'i', 'u', 'y')):
  52.                 pronoun = 'J\''
  53.             print(pronoun + self.verbe[0:-2] + pronouns[p])
  54.  
  55. v = Verbe("écouter")
  56. v.conjuguer("présent")
  57.  
  58. ### EX2
  59.  
  60. ## data
  61. # 065434231031/05/201510h23Salut, t'es ou ?
  62. # 068930405930/05/201511h10Adam t'a laisse un message. Rappelle le sur : 0808432340.
  63. # 065439450301/06/201509h03T'as pas la solution de l'exo 2 ?
  64. # 065439450301/06/201509h40Qu'est-ce que tu fais, y en a marre d'attendre.
  65. # 066032452429/05/201506h30Rdv dans 5 min a la faculte.
  66. # 065343432528/04/201503h20Le nouveau IPHONE a 5000 $ chez Maroc Telecom.
  67. # 052252352303/06/201516h23ADIDAS: PLUS QUE 200 MODELES DISPO CHEZ DECATHLON.
  68.  
  69. from datetime import date, time, timedelta
  70. from os.path import dirname, join
  71.  
  72. def SMS():
  73.     file = open(join(dirname(__file__), 'sms.txt'), "r")
  74.     sms_ = {}
  75.     for sm in file.readline():
  76.         date_ = sm[10:20].split("/")
  77.         time_ = sm[20:25].split("h")
  78.         sms_[sm[:10]] = [
  79.             date(int(date_[2]), int(date_[1]), int(date_[0])),
  80.             time(int(time_[0]), int(time_[1])),
  81.             sm[25:]
  82.         ]
  83.     file.close()
  84.     return sms_
  85.  
  86. def SMS_SPAM(s):
  87.     for sms in list(s):
  88.         if '0808' in s[sms][2]: # regex? from re import search
  89.             s.pop(sms)
  90.     return s
  91.  
  92. def SMS_pub(s):
  93.     pub = []
  94.     for sms in list(s):
  95.         if '$' in s[sms][2]:
  96.             pub.append(sms)
  97.         else:
  98.             maj = [c for c in s[sms][2] if c.isupper()]
  99.             if len(maj) >= len(s[sms][2])/2:
  100.                 pub.append(sms)
  101.     return pub
  102.  
  103. def SMS_noir(s):
  104.     sms = s.copy()
  105.     sms = SMS_pub(SMS_SPAM(sms))
  106.     return [sm for sm in s if sm not in sms]
  107.  
  108. def findMotSMS(s, mot):
  109.     num = []
  110.     for sms in s:
  111.         if mot.lower() in s[sms][2].lower():
  112.             num.append(sms)
  113.     return num
  114.  
  115. def SMSafterDate(s, d):
  116.     date_ = d.split("/")
  117.     date_ = date(int(date_[2]), int(date_[1]), int(date_[0]))
  118.     for s_ in list(s):
  119.         if s[s_][0] + timedelta(weeks = 2) < date_:
  120.             s.pop(s_)
  121.     return s
  122.  
  123. sms = SMS()
  124. # sms_spam = SMS_SPAM(sms)
  125. # sms_pub = SMS_pub(sms)
  126. # sms_noir = SMS_noir(sms)
  127. # chez = findMotSMS(sms, "chez")
  128. after = SMSafterDate(sms, "16/06/2015")
  129. print(after)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement