Programme popularite.py


#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
import urllib
 
from recherche_voila_popularite import *


class Acteur :
    def __init__ (self, nom, prenom, age, nationalite, sexe) :
        self.nom            = nom
        self.prenom         = prenom
        self.age            = age
        self.nationalite    = nationalite
        self.sexe           = sexe
        
        s = "\"" + prenom + " " + nom + "\""
        self.voila          = combien_voila (s)
        self.bing           = combien_bing (s)
        self.ebay           = combien_ebay (s)
        
    def liste_compteur (self) :
        return [ self.voila, self.bing, self.ebay ]
        
print "commencement"        
act = []
act.append ( Acteur ("foster", "jodie", 40, "us", "f") )
act.append ( Acteur ("depardieu", "gerard", 55, "fr", "h") )
act.append ( Acteur ("deneuve", "catherine", 60, "fr", "f") )
act.append ( Acteur ("harrison", "ford", 60, "us", "h") )
if False :  # False pour corriger le programme plus rapidement, True sinon
    act.append ( Acteur ("redford", "robert", 60, "us", "h") )
    act.append ( Acteur ("depp", "johnny", 40, "us", "h") )
    act.append ( Acteur ("eastwoord", "clint", 75, "us", "h") )
    act.append ( Acteur ("sarandon", "susan", 60, "us", "f") )
    act.append ( Acteur ("dunst", "kirsten", 20, "us", "f") )
    act.append ( Acteur ("portman", "nathalie", 25, "us", "h") )
    act.append ( Acteur ("roberts", "julia", 40, "us", "f") )
    act.append ( Acteur ("tautou", "audrey", 30, "fr", "f") )
    act.append ( Acteur ("cotillard", "marion", 30, "fr", "f") )
    act.append ( Acteur ("binoche", "juliette", 40, "fr", "f") )
    act.append ( Acteur ("berry", "richard", 50, "fr", "h") )
    act.append ( Acteur ("bruel", "patrick", 45, "fr", "h") )

def ajoute_liste (l1, l2) :
    for i in range (0, len (l1)) :
        l1 [i] += l2 [i]
    
def divise_liste (l1, s) :
    for i in range (0, len (l1)) :
        l1 [i] /= s
    

# france contre etats - unis
fr = [ 0,0,0 ]
us = [ 0,0,0 ]
nb_fr = 0
nb_us = 0
for a in act :
    print "cherche ", a.nom,
    l = a.liste_compteur ()
    print l
    if a.nationalite == "fr" :
        nb_fr += 1
        ajoute_liste (fr, l)
    if a.nationalite == "us" :
        nb_us += 1
        ajoute_liste (us, l)

divise_liste (us, nb_us) 
divise_liste (fr, nb_fr) 

print "------------------------------"
print "compteur nb_us = ", nb_us, " nb_fr : ", nb_fr
for i in range (0, len (us)) :
    print "us : ", us [i], " \t fr : ", fr [i]

# homme contre femme
f = [ 0,0,0 ]
h = [ 0,0,0 ]
nb_f = 0
nb_h = 0
for a in act :
    print "cherche ", a.nom,
    l = a.liste_compteur ()
    print l
    if a.sexe == "f" :
        nb_f += 1
        ajoute_liste (f, l)
    if a.sexe == "h" :
        nb_h += 1
        ajoute_liste (h, l)

divise_liste (h, nb_h) 
divise_liste (f, nb_f) 

print "------------------------------"
print "compteur nb_h = ", nb_h, " nb_f : ", nb_f
for i in range (0, len (us)) :
    print "h : ", h [i], " \t f : ", f [i]


créé avec py2html version:0.62