import random
def move():
myScore = 0
theirScore = 0
Options=['b','c']
myChoice=random.choice(Options)
theirChoice=random.choice(Options)
if myChoice == 'b' and theirChoice == 'b':
myScore = myScore-250
theirScore = theirScore-250
if myChoice == 'b' and theirChoice == 'c':
myScore = myScore + 100
theirScore = theirScore - 500
if myChoice == 'c' and theirChoice == 'b':
myScore = myScore - 500
theirScore = theirScore + 100
if myChoice == 'c' and theirChoice == 'c':
myScore = myScore + 0
theirScore = theirScore + 0
return myChoice
return myScore
return theirChoice
return theirScore
以上是我用Python编写的代码。它应该随机挑选串通或背叛,用字符串表示' c'和' b'并相应地改变分数,然后返回所做的选择和新分数。这是一次性使用程序,没有输入。以下是我的计划中发生的事情:
In: move
Out: '<function __main__.move>'
我不知道为什么我会得到这个输出,感谢任何帮助,谢谢。
答案 0 :(得分:1)
首先,为了在这里输出任何数据,首先需要提供一个可以解压缩输出的变量。
myChoice = move()
此外,只会运行您的第一个return语句,因此您只会收到&#34; myChoice&#34;功能之外。您可以通过在同一行返回所有四个值来解决此问题:
return (myChoice, myScore, theirChoice, theirScore)
然后您还需要使用函数调用解包所有四个:
(myChoice, myScore, theirChoice, theirScore) = move()