<p>代码中有一些错误:</p>
<ol>
<li>函数中没有实际返回函数值的return语句</li>
<li><p>您有<code>main</code>函数的定义,但它不是从任何地方调用的</p>
<pre><code>if __name__== "__main__":
main()
</code></pre></li>
<li><p>您还需要导入<code>random</code>来使用它</p></li>
</ol>
<p>下面是代码的修改版本,现在可以完美地工作了:</p>
<pre><code>import random
def GetCompHand():
compHand= random.randint(1,3)
if compHand==1:
compHand="r"
elif compHand==2:
compHand="p"
elif compHand==3:
compHand="s"
return compHand
def GetPlayerHand():
Trueinput=False
playerHand= input("Enter r, p, or s:")
while(True):
if playerHand.lower() == "r":
print("You picked rock")
return playerHand
elif playerHand.lower()=="p":
print("You picked paper")
return playerHand
elif playerHand.lower()=="s":
print("You picked scissors")
return playerHand
else:
playerHand= input("Please enter ONLY r, p, or s")
def main():
compHand=GetCompHand()
playerHand=GetPlayerHand()
print(compHand)
print(playerHand)
if __name__== "__main__":
main()
</code></pre>
<p>如果你什么都不懂就告诉我。我很乐意帮助你。谢谢</p>