Ejemplo n.º 1
0
     print 'Kevin Bacon has a Bacon Number of Infinity.' + '\n'
     
 # Exception: if the title of actor_name is 'Kevin Bacon', 
 # return 0 as the Bacon Number. (gets rid of roman numerals)           
 elif bacon_functions.fix_actor_name(actor_name) == 'Kevin Bacon':
     print bacon_functions.fix_actor_name(actor_name) + \
           ' has a Bacon Number of 0.' + '\n'
 
 # For all other cases....
 else:
     
     # If the raw input is not Kevin Bacon, finds actor_name along 
     # with the bacon_number
     actor_name = bacon_functions.fix_actor_name(actor_name)
     bacon_number = bacon_functions.find_bacon_number(\
         bacon_functions.find_connection(actor_name,actor_dict,\
                                        movie_dict),actor_name)
     
     # if the bacon number is infinity, return the following phrase
     if bacon_number == 'Infinity':
         print bacon_functions.fix_actor_name(actor_name) + \
               ' has a Bacon Number of ' + bacon_number + '.' + '\n'
     
     # If Bacon number is a finite number, return that folowing 
     # phrase
     else:
         print bacon_functions.fix_actor_name(actor_name) + \
               ' has a Bacon Number of ' + bacon_number + '.'
     connection_list = bacon_functions.find_connection(actor_name,\
                                                      actor_dict,\
                                                      movie_dict)
     
Ejemplo n.º 2
0
        }
        result = bacon_functions.invert_actor_dict(
            {"Kevin Bacon": ["A Few Good Men (1992)", "Sleepers (1996)"]})
        if expected != result:
            print "Failure of function invert_actor_dict: " + \
                  "Result should be %s, not %s" % (str(expected), str(result))
            ok = False
    else:
        print "Function 'invert_actor_dict' is not defined"
        ok = False

    if hasattr(bacon_functions, 'find_connection'):
        expected = [('Sleepers (1996)', 'Kevin Bacon')]
        result = bacon_functions.find_connection(
            "Robert De Niro", {
                "Kevin Bacon": ["Sleepers (1996)"],
                "Robert De Niro": ["Sleepers (1996)"]
            }, {"Sleepers (1996)": ["Kevin Bacon", "Robert De Niro"]})
        if expected != result:
            print "Failure of function find_connection: " + \
                  "Result should be %s, not %s" % (str(expected), str(result))
            ok = False
    else:
        print "Function 'find_connection' is not defined"
        ok = False

    # No assertions failed, so everything looks okay, at least for the
    # things we checked.
    if ok:
        print "okay"
Ejemplo n.º 3
0
        # When Kevin Bacon is entred, we automatically know the bacon number
        # is 0.

        bacon_num = actor_name + ' has a Bacon Number of 0.'
        print bacon_num
        print ''
        c += 1
        # And the game continues.

    else:

        # If names other than Kevin Bacon are entred, we use find_connection
        # to determine the bacon number and the related actors and movies.

        connection = bacon_functions.find_connection(actor_name, actor_dict,
                                                     movie_dict)
        number = len(connection)
        empty = empty + [number]

        if len(connection) == 0:

            # If there is no connection between the actor and kevin bacon,
            # we say the bacon number is infinity.

            bacon_num = actor_name + ' has a Bacon Number of ' + 'Infinity.'
            print bacon_num

        else:

            # If there is connection between the actor and kevin bacon,
            # we show the bacon number.
Ejemplo n.º 4
0
    largest = 0
    bacon_number = 0
    while bacon_number != -1:
        actor_name = raw_input(
            "Please enter an actor (or press return to exit): ")
        actor_name = bacon_functions.capitalize_name(actor_name)
        if actor_name == "Kevin Bacon":
            print("Kevin Bacon has a Bacon Number of 0.")
        elif actor_name == "":
            print(
                "Thank you for playing! The largest Bacon Number you found was %d."
                % (largest))
            bacon_number = -1
        else:
            full_link = bacon_functions.find_connection(
                actor_name, actors_to_movies, movies_to_actors)
            # The length of the full link represents the distance for any
            # natural number except 0. For the case of 0, either the actor is
            # either 'Kevin Bacon' (already checked above) or the actor has
            # no connection with 'Kevin Bacon'.
            bacon_number = len(full_link)
            if not bacon_number:
                print("%s has a Bacon Number of Infinity." % (actor_name))
            else:
                print("%s has a Bacon Number of %d." %
                      (actor_name, bacon_number))
                previous_actor = actor_name
                for sublink in full_link:
                    movie, actor = sublink
                    print("%s was in %s with %s." %
                          (previous_actor, movie, actor))
Ejemplo n.º 5
0
     
     # When Kevin Bacon is entred, we automatically know the bacon number
     # is 0.
     
     bacon_num = actor_name + ' has a Bacon Number of 0.'
     print bacon_num
     print ''
     c += 1
     # And the game continues.
     
 else:
     
     # If names other than Kevin Bacon are entred, we use find_connection
     # to determine the bacon number and the related actors and movies.
     
     connection = bacon_functions.find_connection(actor_name, 
                                                  actor_dict,movie_dict)           
     number = len(connection)
     empty = empty + [number]
     
     if len(connection) == 0:
         
         # If there is no connection between the actor and kevin bacon,
         # we say the bacon number is infinity.
         
         bacon_num = actor_name + ' has a Bacon Number of ' + 'Infinity.'
         print bacon_num
         
     else:
         
         # If there is connection between the actor and kevin bacon,
         # we show the bacon number.
Ejemplo n.º 6
0
                  "Sleepers (1996)": ["Kevin Bacon"]}
      result = bacon_functions.invert_actor_dict({"Kevin Bacon": ["A Few Good Men (1992)",
                                                        "Sleepers (1996)"]})
      if expected != result:
          print "Failure of function invert_actor_dict: " + \
                "Result should be %s, not %s" % (str(expected), str(result))
          ok = False
   else:
      print "Function 'invert_actor_dict' is not defined"
      ok = False

   if hasattr(bacon_functions, 'find_connection'):
      expected = [('Sleepers (1996)', 'Kevin Bacon')]
      result = bacon_functions.find_connection("Robert De Niro", 
                                     {"Kevin Bacon": ["Sleepers (1996)"],
                                      "Robert De Niro": ["Sleepers (1996)"]},
                                     {"Sleepers (1996)": ["Kevin Bacon", 
                                                          "Robert De Niro"]})
      if expected != result:
          print "Failure of function find_connection: " + \
                "Result should be %s, not %s" % (str(expected), str(result))
          ok = False
   else:
      print "Function 'find_connection' is not defined"
      ok = False

      
   # No assertions failed, so everything looks okay, at least for the
   # things we checked.
   if ok:
      print "okay"
Ejemplo n.º 7
0
Archivo: bacon.py Proyecto: evz/bacon
          ' ...'
    with open('movies_to_actors') as pickled_movies_to_actors:
        movies_to_actors = cPickle.load(pickled_movies_to_actors)

    largest = 0
    bacon_number = 0
    while bacon_number != - 1:
        actor_name = raw_input("Please enter an actor (or press return to exit): ")
        actor_name = bacon_functions.capitalize_name(actor_name)
        if actor_name == "Kevin Bacon":
            print "Kevin Bacon has a Bacon Number of 0."
        elif actor_name == "":
            print "Thank you for playing! The largest Bacon Number you found was %d."%(largest)
            bacon_number = -1
        else:
            full_link = bacon_functions.find_connection(actor_name,actors_to_movies,movies_to_actors)
            # The length of the full link represents the distance for any
            # natural number except 0. For the case of 0, either the actor is
            # either 'Kevin Bacon' (already checked above) or the actor has
            # no connection with 'Kevin Bacon'.
            bacon_number = len(full_link)
            if not bacon_number:
                print "%s has a Bacon Number of Infinity." %(actor_name)
            else:
                print "%s has a Bacon Number of %d." %(actor_name,bacon_number)
                previous_actor = actor_name
                for sublink in full_link:
                    movie,actor = sublink
                    print "%s was in %s with %s."%(previous_actor,movie,actor)
                    previous_actor = actor
        # If the bacon number found for the actor is larger than any bacon