我是新來的python,因爲你可能能夠告訴這個問題。我目前正在構建一個Rock,Paper,Scissors遊戲,以便將來包含到我正在Python 3.4中開發的更大程序中。我遇到的問題是在下面列出的代碼中。意外的縮進和遊戲代碼中的循環
def computerPlayer(): #randomly selects a rock paper or scissor for computer hand
c = random.randint(0, 2)
if c==0:
y=('rock')
if c==1:
y=('scissors')
if c==2:
y==('paper')
return y
在底線回傳義面前時,出現了意外的縮進錯誤,我曾嘗試沒有結果,現在糾正這個在過去的一天,如果我向前移動它,我得到外界的功能「迴歸」,但當我把它移回去時,我得到了意想不到的縮進,我老實說在這裏完全損失,我不知道該去哪裏。任何幫助是非常感謝。
上述問題現在已修復,但我知道有一個循環錯誤之外的休息。它現在出現在我的代碼的末尾。任何幫助非常感謝你。
again = raw_input('do you wish to try again? (yes\no)\n :') #Ask the user if they want play again
if again == ('yes') or again == ('sure') or again == ('okay'):
print ('')
elif again == ('no') or again == ('nah') or again == ('nope') or again == ('screw you') or again == ('screw it'):
print ('FINE THEN!!! =^(\n (Enter>>>game()<<< if you change your mind)')
#breaks the loop
break
game()
縮進在Python是很重要的;函數內只有一條線。 – jonrsharpe
不是你的問題的答案 - 你也可以寫這個函數爲'return random.choice(['rock','scissors','paper'])''。 –
@SvenMarnach嗯,單行實現**是對問題的回答。 –