From 7bd7387282f723ef781d23992b51bbf6934a56b2 Mon Sep 17 00:00:00 2001 From: Aaryadotpy <91911418+AaryaNale@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:16:10 +0530 Subject: [PATCH] Create true_false.py --- True_False_Combinations/true_false.py | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 True_False_Combinations/true_false.py diff --git a/True_False_Combinations/true_false.py b/True_False_Combinations/true_false.py new file mode 100644 index 0000000..9009f2b --- /dev/null +++ b/True_False_Combinations/true_false.py @@ -0,0 +1,30 @@ +from itertools import product + +def generate_variable_combinations(variables): + """ + Generate all possible combinations of True and False values for a given list of variables. + + Args: + variables (list): A list of variable names. + + Returns: + list of tuples: A list of tuples where each tuple represents a combination of True and False + values for the variables. + + Example: + >>> generate_variable_combinations(['A', 'B']) + [(False, False), (False, True), (True, False), (True, True)] + + >>> generate_variable_combinations(['X', 'Y', 'Z']) + [(False, False, False), (False, False, True), (False, True, False), + (False, True, True), (True, False, False), (True, False, True), + (True, True, False), (True, True, True)] + """ + return list(product([False, True], repeat=len(variables))) + +if __name__ == "__main__": + input_variables = input("Enter a list of space-separated variables: ").strip() + variables = input_variables.split() + combinations = generate_variable_combinations(variables) + for combo in combinations: + print(dict(zip(variables, combo)))