You can't.
That's not how computers work.
You have a problem in your logic: you tell the computer to run some code, when you don't actually want it to run that code.
And that is not going to succeed, no matter what programming language you are using.
If you want the computer to "throw" only once, then you must call computer()
only once!
But, since you need the result later, you have to save that result:
import random
def computer():
comp = random.choice([0,1,2])
if comp == 0:
print "Computer throws rock",
elif comp == 1:
print "Computer throws paper"
elif comp == 2:
print "Computer throws scissors"
return comp
comp = computer()
print comp
def throwing(player, comp):
if player == 0:
print "Player throws rock"
elif player == 1:
print "Player throws paper"
elif player == 2:
print "Player throws scissors"
if (player - comp) % 3 > (comp - player) % 3:
print "Computer wins"
elif player == comp:
print "Draw"
else:
print "Player wins"
throwing(0, comp)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…