简体   繁体   中英

Enthought canopy validation error

I need help!! I've been struggling with this problem and I cannot seem to solve it.

def itemName():
    flag = True
        while flag == True:
        try:
            name = input('What would You like to name it? \n')
            Input = str(Input)
            print(name)
            if name.upper() == ('BOAT') or name.upper() == ('CASUALTY'):
                flag = False
            else:
                raise Exception
        except:
            print('Boat or Casualty only')
    return name

name = itemName()
print(name)

This code will not pass when run. This works in the normal python IDLE but not canopy. Also the print statement only outputs if the input is an integer. I'm stumped, any ideas?

This is python 3 code. Canopy uses Python 2.7

The input function differs between these versions.

In python 2.7, the equivalent is raw_input

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