我的函数要求用户输入一个7个字符的数字。但当我定义它时,它不会运行。为什么?任何帮助都将不胜感激。
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)
您必须调用函数,
在代码的最后一行添加一个eticketNum()
,它将是这样的:
def eticketNum():
# your code
eticketNum()
编辑:
如果要使用返回值:
def eticketNum():
# your code
x = eticketNum()
# do whatever you want with 'x' variable.
缩进不正确,选择def行后面的内容并点击"选项卡";在你的键盘上应该可以正常工作,如果java