Home > other >  Pray god help!!!!!! The younger brother just learning soon. How to join in the simulation of competi
Pray god help!!!!!! The younger brother just learning soon. How to join in the simulation of competi

Time:10-04

This is a simulated sport code
From the random import random
Def printIntro () :
Print (" simulation of A and B, A double hit the ball the result of the game ")
Print (" players need to input the ability of A and B values (in the decimal representation) of between 0 and 1 ")
Def getInputs () :
A=eval (input (" please enter the player the ability of a value (0-1) : "))
B=eval (input (" please enter the player the ability of b value (0-1) : "))
N=eval (input (" please input analog double ball game session: "))
Return a, b, n
Def printSummary (winsA winsB) :
N=winsA + winsB
Print (" double shot competitive analysis start!" )
Print (" total simulation {} game! {: * ^ 30} \ n \ n players game win A {}, accounted for 0.1%} {: \ n B {} winning games, accounted for 0.1%} {: ". The format (n, "result", winsA, winsA/n, winsB, winsB/n))
Def simNGames (n, proA, proB) :
WinsA, winsB=0, 0
For I in range (n) :
ScoreA, scoreB=simOneGame (proA, proB)
If scoreA & gt; ScoreB:
WinsA +=1
The else:
WinsB +=1
Return winsA, winsB
Def simOneGame (proA, proB) :
ScoreA, scoreB=0, 0
Serving="A"
While not gameOver (scoreA scoreB) :
If serving=="A" :
If the random () & lt; ProA:
ScoreA +=1
The else:
Serving="B"
The else:
If the random () & lt; ProB:
ScoreB +=1
The else:
Serving="A"
Return scoreA, scoreB
Def gameOver (a, b) :
Return a 15 or b====15
Def the main () :
PrintIntro ()
ProA, proB, n=getInputs ()
WinsA, winsB=simNGames (n, proA, proB)
PrintSummary (winsA, winsB)
The main ()

CodePudding user response:

Try to add a while loop,

Win a game for a minute,

One side to get three points out of circulation,
  • Related