我不知道为什么会出现意外的EOF。我觉得缩进都是正确的,但是由于某种原因,返回值链接到if-elif ... if有意义的地方。在eclipse中,它具有链接所有语句的行。
def randomCard():
num1 = random.randint(1, 13)
num2 = random.randint(1, 4)
cardnum1 = ""
cardnum2 = ""
if num1 == 11:
cardnum1 = "Q"
elif num1 == 12:
cardnum1 = "J"
elif num1 == 13:
cardnum1 = "K"
elif num1 < 10:
cardnum1 = str(num1)
else:
cardnum1 = '10'
if num2 == 1:
cardnum2 = "S"
elif num2 == 2:
cardnum2 = "H"
elif num2 == 3:
cardnum2 = "D"
elif num2 == 4:
cardnum2 = "C"
else:
cardnum2 = 'S'
return cardnum1 + cardnum2
结果应该是函数2-A和西装S,H,D,C image of the problem code in eclipse所返回的随机卡片