我想在 PYTHON 中创建一个 Scissor Paper Rock 程序。它工作但是,它在最后继续打印 "none"
I want to create a Scissor Paper Rock program in PYTHON. It worked BUT, It keeps on printing "none" at the end
我找不到显示消息后一直打印的“NONE”
whats your move on "scissor" "paper" and "rock" ?!
rock
computer-paper
sorry man you lost
None
message={
"loose":"sorry man you lost",
"win":"YOU WIN ",
"tie":"it's a tie"
}
def game(user,comp):
if user==comp:
print(message.get("tie"))
elif user=="scissor" and comp=="paper":
print(message.get("win"))
elif user=="paper" and comp=="rock":
print(message.get("win"))
elif user=="rock" and comp=="scissor":
print(message.get("win"))
else:
print(message.get("loose"))
user=input('''what's your move on "scissor" "paper" and "rock" ?!\n ''')
import random
comp=random.randint(1,3)
if comp==1:
comp="scissor"
elif comp==2:
comp="paper"
elif comp==3:
comp="rock"
print("computer-",comp)
x=(game(user,comp))
print(x)
game()
函数会打印内容,但不会 return 任何内容。
所以当你打印 game()
的 return 值时,你打印 None.
我找不到显示消息后一直打印的“NONE”
whats your move on "scissor" "paper" and "rock" ?!
rock
computer-paper
sorry man you lost
None
message={
"loose":"sorry man you lost",
"win":"YOU WIN ",
"tie":"it's a tie"
}
def game(user,comp):
if user==comp:
print(message.get("tie"))
elif user=="scissor" and comp=="paper":
print(message.get("win"))
elif user=="paper" and comp=="rock":
print(message.get("win"))
elif user=="rock" and comp=="scissor":
print(message.get("win"))
else:
print(message.get("loose"))
user=input('''what's your move on "scissor" "paper" and "rock" ?!\n ''')
import random
comp=random.randint(1,3)
if comp==1:
comp="scissor"
elif comp==2:
comp="paper"
elif comp==3:
comp="rock"
print("computer-",comp)
x=(game(user,comp))
print(x)
game()
函数会打印内容,但不会 return 任何内容。
所以当你打印 game()
的 return 值时,你打印 None.