2015-11-23 101 views
1
def intro(): 

    global skips 
    skips = 3 
    print ('skip') 
    skips = int(input()) 
    if 'skip' in skips: 
     skips - 1 
     if skips > 0: 
      print('you are out of skips') 
      end() 
     if skips < 0: 
      print ('You have ' ,skips, ' left') 

    intro() 
def end(): 
    print ('you are out of skips. Game Over') 

intro() 

我想它也帶走(1個跳過)每當有人類型(跳過)。並且每次運行程序時,我都希望它檢查是否有足夠的空間(跳過)。幫助將不勝感激。ValueError異常:無效的基數爲10字面INT(): '跳過'

+0

你怎麼知道有人輸入「跳」? –

+2

'skips - 1' does not nothing ... – Tempux

+1

發生錯誤是因爲你輸入了「skip」,它是通過input()讀取的,然後傳遞給int(),它試圖轉換爲整數, ValueError' –

回答

1

這是更接近你想要什麼:

def intro(skips=3): 
    print ('skip') 
    answer = input() 
    if 'skip' in answer: 
     skips -= 1 
     if skips <= 0: 
      print('you are out of skips') 
      end() 
     elif skips > 0: 
      print ('You have ' ,skips, ' left') 
      intro(skips) 
def end(): 
    print ('you are out of skips. Game Over') 

intro() 
+0

謝謝。這是我想要的。 –

相關問題