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>'我不知道为什么我会得到这个输出,任何帮助我都很感激,谢谢。
发布于 2016-11-03 01:22:48
首先,为了在这里有任何输出,您首先需要提供一个变量,输出可以解包到该变量中。
myChoice = move()此外,只会运行第一个返回语句,因此您只会在函数外部收到"myChoice“的值。您可以通过在同一行上返回所有四个值来解决此问题:
return (myChoice, myScore, theirChoice, theirScore)然后,您还需要使用函数调用将这四个包都解压缩:
(myChoice, myScore, theirChoice, theirScore) = move()https://stackoverflow.com/questions/40385891
复制相似问题