简体   繁体   中英

ValueError: invalid literal for int() with base 10: 'skip'

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()

I want it too take away (1 skips ) every time someone types ( skip ). And every time it runs through the program I want it to check to see if has enough ( skips ). Help would be greatly appreciated.

This is closer to what you want:

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM