擅长:python、mysql、java
<pre><code>import random
def newfunc(string1, string2):
if string1 == string2:
print "You selected",string1,"and the computer selected",string2,"you win!"
else:
print "You selected",string1,"and the computer selected",string2,"you lose!"
def AceDiamondSpade():
#Set up a list which contains Ace, Diamond and Spade so that the computer can randomly choose one of them.
myList = ["Ace", "Diamond", "Spade"]
#
while(True):
choice = raw_input("Ace, Diamond, or Spade? ")
computerChoice = random.choice(myList)
if choice not in myList:
print "That was not a valid choice."
break
newfunc(choice,computerChoice)
AceDiamondSpade()
</code></pre>
<p>这是基于diegaoguilar的回答,但它增加了一个新功能的前景。在</p>
<p>我敢肯定你只是直接把代码复制/粘贴到网站上,但是要小心缩进,如果可能的话,在行间留出一些间隔,这样会使阅读变得更容易。在</p>