石头剪刀Python程序:winOrLose()接受两个参数(给定0)
我正在编写一个程序,与用户一起玩石头剪刀。我必须运行这个程序5次。我正在使用python。每当我运行程序并键入“R”、“S”或“P”时,程序将导致错误:石头剪刀Python程序:winOrLose()接受两个参数(给定0),python,loops,if-statement,for-loop,while-loop,Python,Loops,If Statement,For Loop,While Loop,我正在编写一个程序,与用户一起玩石头剪刀。我必须运行这个程序5次。我正在使用python。每当我运行程序并键入“R”、“S”或“P”时,程序将导致错误: TypeError: winOrLose() takes exactly 2 arguments (0 given) 下面是我的程序: from myro import * from random import * def userOptions(): print "Press R for Rock" p
TypeError: winOrLose() takes exactly 2 arguments (0 given)
下面是我的程序:
from myro import *
from random import *
def userOptions():
print "Press R for Rock"
print "Press P for Paper"
print "Press S for Scissors"
choice = raw_input("Your choice is: ")
if choice == "R":
return "Rock"
if choice == "P":
return "Paper"
if choice == "S":
return "Scissors"
else:
userOptions()
def computerRandom():
options = ["Rock", "Paper", "Scissors"]
cGuess = randint(0,2)
return options[cGuess]
def winOrLose(userChoice, computerChoice):
if userChoice == computerChoice:
return "Tie"
if userChoice == "Rock" and computerChoice == "Paper":
return "Computer Wins"
if userChoice == "Paper" and computerChoice == "Scissors":
return "Computer Wins"
if userChoice == "Scissors" and computerChoice == "Rock":
return "Computer Wins"
else:
return "User Wins"
while True:
userChoice = userOptions()
computerChoice = computerRandom()
print "User Chose: ", userChoice
print "Computer Chose: ", computerChoice
result = winOrLose(userChoice, computerChoice)
if result == "Tie":
print "It is a tie"
elif result == "Computer Wins":
print "Computer Wins"
else:
print "User Wins"
def main():
for index in range(1,5,1):
speak("Rock Paper Scissors Shoot")
userOptions()
computerRandom()
winOrLose()
main()
请有人帮帮我,我现在有点急着想办法解决这个问题
谢谢如错误中所述,您没有将参数传递给函数winOrLose 在你的主要职能中
def main():
for index in range(1,5,1):
...
...
winOrLose() # in this statement you are not passing any arguments
按照错误中的说明,您没有将参数传递给函数winOrLose 在你的主要职能中
def main():
for index in range(1,5,1):
...
...
winOrLose() # in this statement you are not passing any arguments
按照错误中的说明,您没有将参数传递给函数winOrLose 在你的主要职能中
def main():
for index in range(1,5,1):
...
...
winOrLose() # in this statement you are not passing any arguments
按照错误中的说明,您没有将参数传递给函数winOrLose 在你的主要职能中
def main():
for index in range(1,5,1):
...
...
winOrLose() # in this statement you are not passing any arguments
我认为您在调用winOrLose()时没有任何参数,尽管定义中说
def winOrLose(userChoice,computerChoice):
。您应该将值userChoice,computerChoice
放在methodcall中 我认为您在调用winOrLose()时没有任何参数,尽管定义中说def winOrLose(userChoice,computerChoice):
。您应该将值userChoice,computerChoice
放在methodcall中 我认为您在调用winOrLose()时没有任何参数,尽管定义中说def winOrLose(userChoice,computerChoice):
。您应该将值userChoice,computerChoice
放在methodcall中 我认为您在调用winOrLose()时没有任何参数,尽管定义中说def winOrLose(userChoice,computerChoice):
。您应该将值userChoice,computerChoice
放在methodcall中 错误消息告诉您,您需要为winOrLose
函数提供两个参数。从userOptions()
和computerRandom()
返回值,但未将这些值分配给任何变量:
def main():
for index in range(1,5,1):
speak("Rock Paper Scissors Shoot")
user_choice = userOptions()
computer_choice = computerRandom()
winOrLose(user_choice, computer_choice)
main()
错误消息告诉您,您需要为
winOrLose
函数提供两个参数。从userOptions()
和computerRandom()
返回值,但未将这些值分配给任何变量:
def main():
for index in range(1,5,1):
speak("Rock Paper Scissors Shoot")
user_choice = userOptions()
computer_choice = computerRandom()
winOrLose(user_choice, computer_choice)
main()
错误消息告诉您,您需要为
winOrLose
函数提供两个参数。从userOptions()
和computerRandom()
返回值,但未将这些值分配给任何变量:
def main():
for index in range(1,5,1):
speak("Rock Paper Scissors Shoot")
user_choice = userOptions()
computer_choice = computerRandom()
winOrLose(user_choice, computer_choice)
main()
错误消息告诉您,您需要为
winOrLose
函数提供两个参数。从userOptions()
和computerRandom()
返回值,但未将这些值分配给任何变量:
def main():
for index in range(1,5,1):
speak("Rock Paper Scissors Shoot")
user_choice = userOptions()
computer_choice = computerRandom()
winOrLose(user_choice, computer_choice)
main()
在主函数中不传递任何参数
def main():
for index in range(1,5,1):
speak("Rock Paper Scissors Shoot")
userOptions()
computerRandom()
winOrLose()
应该是:
def main():
for index in range(1,5,1):
speak("Rock Paper Scissors Shoot")
userChoice = userOptions()
computerChoice = computerRandom()
winOrLose(userChoice, computerChoice)
另一个问题是,对于范围(1,5,1)中的索引,您尝试使用运行它5次,但在winOrLose
函数中有一个无限循环,因此在第一次调用它之后,您永远不会退出:
def winOrLose(userChoice, computerChoice):
if userChoice == computerChoice:
return "Tie"
if userChoice == "Rock" and computerChoice == "Paper":
return "Computer Wins"
if userChoice == "Paper" and computerChoice == "Scissors":
return "Computer Wins"
if userChoice == "Scissors" and computerChoice == "Rock":
return "Computer Wins"
else:
return "User Wins"
while True: # <=== infinite loop here.
userChoice = userOptions()
computerChoice = computerRandom()
print "User Chose: ", userChoice
print "Computer Chose: ", computerChoice
result = winOrLose(userChoice, computerChoice)
if result == "Tie":
print "It is a tie"
elif result == "Computer Wins":
print "Computer Wins"
else:
print "User Wins"
在主函数中不传递任何参数
def main():
for index in range(1,5,1):
speak("Rock Paper Scissors Shoot")
userOptions()
computerRandom()
winOrLose()
应该是:
def main():
for index in range(1,5,1):
speak("Rock Paper Scissors Shoot")
userChoice = userOptions()
computerChoice = computerRandom()
winOrLose(userChoice, computerChoice)
另一个问题是,对于范围(1,5,1)
中的索引,您尝试使用运行它5次,但在winOrLose
函数中有一个无限循环,因此在第一次调用它之后,您永远不会退出:
def winOrLose(userChoice, computerChoice):
if userChoice == computerChoice:
return "Tie"
if userChoice == "Rock" and computerChoice == "Paper":
return "Computer Wins"
if userChoice == "Paper" and computerChoice == "Scissors":
return "Computer Wins"
if userChoice == "Scissors" and computerChoice == "Rock":
return "Computer Wins"
else:
return "User Wins"
while True: # <=== infinite loop here.
userChoice = userOptions()
computerChoice = computerRandom()
print "User Chose: ", userChoice
print "Computer Chose: ", computerChoice
result = winOrLose(userChoice, computerChoice)
if result == "Tie":
print "It is a tie"
elif result == "Computer Wins":
print "Computer Wins"
else:
print "User Wins"
在主函数中不传递任何参数
def main():
for index in range(1,5,1):
speak("Rock Paper Scissors Shoot")
userOptions()
computerRandom()
winOrLose()
应该是:
def main():
for index in range(1,5,1):
speak("Rock Paper Scissors Shoot")
userChoice = userOptions()
computerChoice = computerRandom()
winOrLose(userChoice, computerChoice)
另一个问题是,对于范围(1,5,1)
中的索引,您尝试使用运行它5次,但在winOrLose
函数中有一个无限循环,因此在第一次调用它之后,您永远不会退出:
def winOrLose(userChoice, computerChoice):
if userChoice == computerChoice:
return "Tie"
if userChoice == "Rock" and computerChoice == "Paper":
return "Computer Wins"
if userChoice == "Paper" and computerChoice == "Scissors":
return "Computer Wins"
if userChoice == "Scissors" and computerChoice == "Rock":
return "Computer Wins"
else:
return "User Wins"
while True: # <=== infinite loop here.
userChoice = userOptions()
computerChoice = computerRandom()
print "User Chose: ", userChoice
print "Computer Chose: ", computerChoice
result = winOrLose(userChoice, computerChoice)
if result == "Tie":
print "It is a tie"
elif result == "Computer Wins":
print "Computer Wins"
else:
print "User Wins"
在主函数中不传递任何参数
def main():
for index in range(1,5,1):
speak("Rock Paper Scissors Shoot")
userOptions()
computerRandom()
winOrLose()
应该是:
def main():
for index in range(1,5,1):
speak("Rock Paper Scissors Shoot")
userChoice = userOptions()
computerChoice = computerRandom()
winOrLose(userChoice, computerChoice)
另一个问题是,对于范围(1,5,1)
中的索引,您尝试使用运行它5次,但在winOrLose
函数中有一个无限循环,因此在第一次调用它之后,您永远不会退出:
def winOrLose(userChoice, computerChoice):
if userChoice == computerChoice:
return "Tie"
if userChoice == "Rock" and computerChoice == "Paper":
return "Computer Wins"
if userChoice == "Paper" and computerChoice == "Scissors":
return "Computer Wins"
if userChoice == "Scissors" and computerChoice == "Rock":
return "Computer Wins"
else:
return "User Wins"
while True: # <=== infinite loop here.
userChoice = userOptions()
computerChoice = computerRandom()
print "User Chose: ", userChoice
print "Computer Chose: ", computerChoice
result = winOrLose(userChoice, computerChoice)
if result == "Tie":
print "It is a tie"
elif result == "Computer Wins":
print "Computer Wins"
else:
print "User Wins"
这是课程《python交互式编程入门》中的一个问题吗?我似乎还记得这一点,主函数最后一行的winOrLose()函数就是问题所在,给它2个参数这是课程中的一个问题-python交互式编程入门
?我似乎还记得这一点,主函数最后一行的winOrLose()函数就是问题所在,给它2个参数这是课程中的一个问题-python交互式编程入门
?我似乎还记得这一点,主函数最后一行的winOrLose()函数就是问题所在,给它2个参数这是课程中的一个问题-python交互式编程入门
?我似乎记得这一点,主函数最后一行的winOrLose()函数就是问题所在,给它两个参数