How do I print these return values from function in Python 3? -


i have homework assignment raquetball simulation. i'm trying figure out how expand program account shutouts , return number each player. added loop simngames() count shutouts. i'd return values , print them out in summary.

    def simngames(n, proba, probb):     winsa = 0     winsb = 0     shutouta = 0     shutoutb = 0     in range(n):         scorea, scoreb = simonegame(proba, probb)         if scorea > scoreb:             winsa = winsa + 1         else:             winsb = winsb + 1     in range(n):         scorea, scoreb = simonegame(proba, probb)         if scorea == 15 , scoreb == 0:             shutouta = shutouta + 1         if scorea == 0 , scoreb == 15:             shutoutb = shutoutb + 1          return winsa, winsb, shutouta, shutoutb ## program breaks when add                                                 ## shutouta, , shutoutb return val                                             

if steer me in right direction it'd appreciated. valueerror: many values unpack (expected 2), when add shutouts return value. here entire program:

from random import random  def main():     proba, probb, n = getinputs()     winsa, winsb = simngames(n, proba, probb)     printsummary(winsa, winsb)   def getinputs():     = eval(input("what probability player wins serve? "))     b = eval(input("what probablity player b wins serve? "))     n = eval(input("how many games playing? "))     return a, b, n    def simngames(n, proba, probb):     winsa = 0     winsb = 0     shutouta = 0     shutoutb = 0     in range(n):         scorea, scoreb = simonegame(proba, probb)         if scorea > scoreb:             winsa = winsa + 1         else:             winsb = winsb + 1     in range(n):         scorea, scoreb = simonegame(proba, probb)         if scorea == 15 , scoreb == 0:             shutouta = shutouta + 1         if scorea == 0 , scoreb == 15:             shutoutb = shutoutb + 1          return winsa, winsb   def simonegame(proba, probb):     serving = "a"     scorea = 0     scoreb = 0     while not gameover(scorea, scoreb):         if serving == "a":             if random() < proba:                 scorea = scorea + 1             else:                 serving = "b"          else:             if random() < probb:                 scoreb = scoreb + 1             else:                 serving = "a"     return scorea, scoreb  def gameover(a, b):     return == 15 or b == 15  def printsummary(winsa, winsb):     n = winsa + winsb     print("\ngames simulated:", n)     print("wins a: {0} ({1:0.1%})".format(winsa, winsa/n))     print("wins b: {0} ({1:0.1%})".format(winsb, winsb/n))   if __name__ == '__main__': main()    

when call function:

winsa, winsb = simngames(n, proba, probb) 

you're expecting 2 values (winsa, winsb), returning four.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -