简体   繁体   中英

I defined my funtion but it wont run. why not?

My function that asks the user to input a 7 character number. but when i define it, it wont run. reason why? any help is appreciated.

def eticketNum():
    while True:
        eTickNum = input('please enter eticket number:')
        if len(eTickNum) == 7:
            break
        print ('Sorry, entry is invalid. Your e-ticket number has to be 7 characters long.')
    eTickNum = eTickNum.lower()
    # next part of function (I guess)

You have to call the function,
add a eticketNum() to the last line of your code, It will be something like this:

def eticketNum():
    # your code
eticketNum()

edit:
if you want to use return value:

def eticketNum():
    # your code
x = eticketNum()
# do whatever you want with 'x' variable.

Indentation is not correct, select what's after the def line and hit "tab" on your keyboard should work fine it's the alternative for {} if java

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-2025 STACKOOM.COM