Question
The problem with this code is that it doesn't accept the input from the user (i.e. console). The output should be in the console. Fix
The problem with this code is that it doesn't accept the input from the user (i.e. console). The output should be in the console. Fix the code so it accepts input from user and returns the proper output. Or create own code. Thanks
import itertools
def CatesianList(List): element = [] for e in itertools.product(*List): element.append(e) return element
def transitive_closure(TranList): Tran_Closure = set(TranList) while True: new_relations = set((x,w) for x,y in Tran_Closure for q,w in Tran_Closure if q == y)
closure_until_now = Tran_Closure | new_relations
if closure_until_now == Tran_Closure: break
Tran_Closure = closure_until_now
return Tran_Closure
def main(): List = [{0 , 1},{1 , 2}] CatesianProductList = CatesianList(List) print (CatesianProductList) TranList = ([(1, 2),(2 , 3),(2, 4)]) transitive = transitive_closure(TranList) print (transitive)
if __name__=="__main__": main()
Python Programming Help- Please provide structured code for 1f and 1g and screenshot of output for each. Thankss 1f) cartesianproduct: This function should accept a list of one or more sets or frozensets (you can convert between them using set fro st) and frozenset (st)). Its output is a set or frozenset encoding the cartesian product; thus a list of two sets [f0,1}, (1,211could give back ( (0,1), (0,2),(1,1), (1,2)}. In general, an input list of length N will yield a set of tuples of length N each. 1g) transitiveclosure: This function should accept sets/frozensets of 2- tuples that encode relations, or equivalently, graphs, and should return the least relation that includes the input relation and is transitive: its transitive closure. E.g., an input frozenset(t (1,2), (2,3)}) could correctly result in the value frozenset( (1,2), (2,3), (1,3))Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started