我对python很陌生。我需要有人帮助我在 python 中运行一个简单的脚本。我有一个我附上的代码。我是定义函数和运行 if else 函数的新手,所以我需要有关如何使以下函数工作的帮助?
我不知道是否有必要定义不同的函数,我知道我在下面的代码中的很多行都错了。我需要有人帮我修改它
def values():
p1g = float(input("Player 1 Utility for green"))
p2r = float(input("Player 2 ulitity for red"))
p1r = float(input("Player 1 utility for red"))
p2g = float(input("Player 2 utility for green"))
d1 = float(input("Player 1 Disagreement point"))
d2 = float (input("Player 2 Disagreement point"))
return [p1g,p2r,p14,p2g,d1,d2]
def slope_int(p1g,p2r,p1r,p2g):
"""Returns the slope and intercept of the payoff/utilities"""
m = (p2g-p2r)/(p1r-p1g)
c = p2r - ((p2g-p2r)/(p1r-p1g))* p1g
return [m,c]
def nash_bargaining_x(p1g,p2r,p1r,p2g,d1,d2,m,c):
return -(p2r -d2 - m*p1g - m*d1)/2*m
def nash_bargaining_y(p1g,p2r,p1r,p2g,d1,d2,m,c):
return -(p2r -d2 - m*p1g - m*d1) + c # where c = p1g-p2r*((p2g-p2r)/(p1r-p1g)
solution = [nash_bargaining_x(),nash_bargaining_y()]
print (solution)
if abs.(p1g-nash_bargaining_x) > (p1r-nash_bargaining_x):
solution = "P1 has Red"
else:
solution = "P2 has red"
期望程序计算脚本中列出的所有值并返回用户输入变量所需的值。