Information, calcul, communication

CS-119(k)

ICC-P Code pour exercice 1

This page is part of the content downloaded from ICC-P Code pour exercice 1 on Sunday, 29 June 2025, 20:43. Note that some content and any files larger than 50 MB are not downloaded.

Page content

Code:
# MyLittleFacebook friendships: dict[str, set[str]] = {} def add_friends(name1: str, name2: str) -> None: if name1 in friendships: friendships[name1].add(name2) else: friendships[name1] = {name2} if name2 in friendships: friendships[name2].add(name1) else: friendships[name2] = {name1} add_friends("Alex", "Victor") add_friends("Alex", "Emelyne") add_friends("Alex", "Emelyne") add_friends("Emelyne", "Rose") # Tests pour (b) # print(friends_of("Emelyne")) # {'Rose', 'Alex'} # print(friends_of("Rachel")) # set() # Tests pour (c) # print(are_friends("Alex", "Victor")) # True # print(are_friends("Victor", "Alex")) # True # print(are_friends("Alex", "Rose")) # False # print(are_friends("Alex", "Rachel")) # False # print(are_friends("Rachel", "Alex")) # False # Tests pour (d) # print(f"Consistent before modification? {is_data_consistent()}") # True # friendships["Alex"].add("Rachel") # Modification asymétrique # print(f"Consistent after modification? {is_data_consistent()}") # False