Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### EX1
- # 2015
- class Vecteur2D:
- def __init__(self, x = 0, y = 0):
- self.x = x
- self.y = y
- def affiche(self):
- print(self.x, ',', self.y)
- def __add__(self, v):
- return Vecteur2D(self.x + v.x, self.y + v.y)
- v1 = Vecteur2D(2, 3)
- v2 = Vecteur2D(3, 4)
- v3 = v1 + v2
- v3.affiche()
- # 2019
- class Verbe:
- def __init__(self, verbe):
- self.verbe = verbe.lower.strip()
- def type(self):
- groupe = "troisième"
- if self.verbe[-2:] == 'er':
- groupe = 'premier'
- if self.verbe[-2:] == 'ir':
- groupe = 'deuxième'
- return(groupe)
- def affiche(self):
- print(self.verbe)
- def conjuguer(self, temps):
- ppgp = {
- 'Je': 'e',
- 'Tu': 'es',
- 'Il': 'e',
- 'Nous': 'ons',
- 'Vous': 'ez',
- 'Ils': 'ent'
- }
- if temps == 'présent' and self.type() == 'premier':
- pronouns = ppgp
- for p in pronouns:
- pronoun = p + ' '
- if(p == 'Je' and self.verbe[0] in ('e', 'é', 'a', 'o', 'i', 'u', 'y')):
- pronoun = 'J\''
- print(pronoun + self.verbe[0:-2] + pronouns[p])
- v = Verbe("écouter")
- v.conjuguer("présent")
- ### EX2
- ## data
- # 065434231031/05/201510h23Salut, t'es ou ?
- # 068930405930/05/201511h10Adam t'a laisse un message. Rappelle le sur : 0808432340.
- # 065439450301/06/201509h03T'as pas la solution de l'exo 2 ?
- # 065439450301/06/201509h40Qu'est-ce que tu fais, y en a marre d'attendre.
- # 066032452429/05/201506h30Rdv dans 5 min a la faculte.
- # 065343432528/04/201503h20Le nouveau IPHONE a 5000 $ chez Maroc Telecom.
- # 052252352303/06/201516h23ADIDAS: PLUS QUE 200 MODELES DISPO CHEZ DECATHLON.
- from datetime import date, time, timedelta
- from os.path import dirname, join
- def SMS():
- file = open(join(dirname(__file__), 'sms.txt'), "r")
- sms_ = {}
- for sm in file.readline():
- date_ = sm[10:20].split("/")
- time_ = sm[20:25].split("h")
- sms_[sm[:10]] = [
- date(int(date_[2]), int(date_[1]), int(date_[0])),
- time(int(time_[0]), int(time_[1])),
- sm[25:]
- ]
- file.close()
- return sms_
- def SMS_SPAM(s):
- for sms in list(s):
- if '0808' in s[sms][2]: # regex? from re import search
- s.pop(sms)
- return s
- def SMS_pub(s):
- pub = []
- for sms in list(s):
- if '$' in s[sms][2]:
- pub.append(sms)
- else:
- maj = [c for c in s[sms][2] if c.isupper()]
- if len(maj) >= len(s[sms][2])/2:
- pub.append(sms)
- return pub
- def SMS_noir(s):
- sms = s.copy()
- sms = SMS_pub(SMS_SPAM(sms))
- return [sm for sm in s if sm not in sms]
- def findMotSMS(s, mot):
- num = []
- for sms in s:
- if mot.lower() in s[sms][2].lower():
- num.append(sms)
- return num
- def SMSafterDate(s, d):
- date_ = d.split("/")
- date_ = date(int(date_[2]), int(date_[1]), int(date_[0]))
- for s_ in list(s):
- if s[s_][0] + timedelta(weeks = 2) < date_:
- s.pop(s_)
- return s
- sms = SMS()
- # sms_spam = SMS_SPAM(sms)
- # sms_pub = SMS_pub(sms)
- # sms_noir = SMS_noir(sms)
- # chez = findMotSMS(sms, "chez")
- after = SMSafterDate(sms, "16/06/2015")
- print(after)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement