#Problema decisional "escolha de projecto" #Classe "jogo de azar" class gamble: def__init__(self,name,consequence,probability): self.name = name self.consequence = consequence self.probability = probability #Classe "automato" class automaton: def__init__(self,alternatives,probabilities,expectations,chosen): self.results = alternatives self.probabilities = probabilities self.expectations = expectations self.chosen = chosen #Método de formação de Expectativas def FormExpectation (self): NumAlternatives = len(self.alternatives) for i in range(0,NumAlternatives) A = self.alternatives [1] Prob = self.probabilities [i] LenA = len(A) Weigh = [] for j in range(0,LenA): Weigh = Weigh + [A[j] * Prob [j]] self.expectations = self.expectations + [sum(Weigh)] #Método de Selecção das Alternativas def choose(self,NameAlt): M = max(self.expectations) for i in range(0,len(self.expectations)): if self.expectations[i] == M: self.choice = NameAlt[i] self.chosen = self.chosen + [NameAlt[i]] print("\nThe chosen alternatives are:") for j in range(0,len(self.chosen)): print(self.chosen[j]) print("\nWith associated expectation: "+str(M))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question