即時通訊使用python編程語言的初學者,並且我無法在python中編寫簡單的程序,我可以在終端中運行。這是迄今爲止的計劃。python終端打印變量
import random
X = "*"
O = "*"
Player = "*"
Computer = "*"
def inputPlayerLetter():
letter = raw_input('Do you want to be X or O? \n')
if letter == "X":
print "You are now X's, you will go first"
Player = "X"
Computer = "O"
elif letter == "O":
print "You are now O's you will go second"
Player = "O"
Computer = "X"
inputPlayerLetter()
print Player
print Computer
這就是我在終端上運行代碼時得到的結果。
Do you want to be X or O?
X
You are now X's, you will go first
*
*
或
Do you want to be X or O?
O
You are now O's you will go second
*
*
基本上,我的功能,如果我選擇X,我想球員是X,和電腦是O(或當我選擇O,我希望球員是O和計算機X)。但是,當我打印這個變量時,我得到了*和*。我該如何解決這個問題,以便我從elif語句中得到我想要的效果。
這是一個範圍問題 – keyser 2014-12-13 15:44:07