Python 中第二个定义的语法错误
Syntax error at second definition in Python
def specificChecker(someThing, checker):
if checker == None:
return someThing
elif checker == True:
return not someThing
else:
return None
def whatDoesTheCheckerSay(someThing):
if specificChecker(someThing) == someThing:
return 'The checker value was False on that one.'
elif specificChecker(someThing) == not someThing:
return 'The checker value was True on that one.'
elif specificChecker(someThing) == None:
return 'Something irregular happend. The checker value wasn\'t None or True.'
else:
return 'Something went really wrong. This doesn\'t even not work.'
reallySomeThing = input('Type in really some thing: ')
theChecker = input('Set the checker to something: ')
print(specificChecker(reallySomeThing, theChecker))
print(whatDoesTheCheckerSay(reallySomeThing)) # This can be made more efficient, right?
def one(someShit):
return someShit + ' AWWW YEAH!'
def two(someShit):
return one(someShit)
print(two(input('Type in some kind of stuff: ')))
我是一个自学成才的初学者,所以这肯定是一些笨拙的基础知识。我正在使用 IDLE shell 并且在我的代码的第二个定义语句中反复出现语法错误。请帮忙?
您不能使用以下行:
elif specificChecker(someThing) == not someThing:
这个一定要写
elif specificChecker(someThing) != someThing:
有效Python.
这也是有效的,但可能不太可读:
elif (specificChecker(someThing)) == (not someThing):
OP编辑后:
新错误是参数(始终为 1)与需要 2 个参数的函数不匹配。您必须将两个参数传递给 specificChecker
而不是一个
第 12 行:elif specificChecker(someThing) == not someThing:
如果你想检查某个变量是否不是某个变量,使用 is not
布尔值或 !=
值和字符串
def specificChecker(someThing, checker):
if checker == None:
return someThing
elif checker == True:
return not someThing
else:
return None
def whatDoesTheCheckerSay(someThing):
if specificChecker(someThing) == someThing:
return 'The checker value was False on that one.'
elif specificChecker(someThing) == not someThing:
return 'The checker value was True on that one.'
elif specificChecker(someThing) == None:
return 'Something irregular happend. The checker value wasn\'t None or True.'
else:
return 'Something went really wrong. This doesn\'t even not work.'
reallySomeThing = input('Type in really some thing: ')
theChecker = input('Set the checker to something: ')
print(specificChecker(reallySomeThing, theChecker))
print(whatDoesTheCheckerSay(reallySomeThing)) # This can be made more efficient, right?
def one(someShit):
return someShit + ' AWWW YEAH!'
def two(someShit):
return one(someShit)
print(two(input('Type in some kind of stuff: ')))
我是一个自学成才的初学者,所以这肯定是一些笨拙的基础知识。我正在使用 IDLE shell 并且在我的代码的第二个定义语句中反复出现语法错误。请帮忙?
您不能使用以下行:
elif specificChecker(someThing) == not someThing:
这个一定要写
elif specificChecker(someThing) != someThing:
有效Python.
这也是有效的,但可能不太可读:
elif (specificChecker(someThing)) == (not someThing):
OP编辑后:
新错误是参数(始终为 1)与需要 2 个参数的函数不匹配。您必须将两个参数传递给 specificChecker
而不是一个
第 12 行:elif specificChecker(someThing) == not someThing:
如果你想检查某个变量是否不是某个变量,使用 is not
布尔值或 !=
值和字符串