def guessr(inpt):
guess = input("type something: ")
print(guess)
if type(guess) == str:
print("is a string")
elif type(guess) == int or type(guess) == float:
print("is a number")
else:
print("i don't know")
return()
def guessr(67)
大家好,您能帮我吗?此代码无法运行,我收到此错误:
file "main.py", line 12
def guessr(67)
syntax error: invalid syntax
也许只是python版本的问题,因为我习惯于在python2.7中编程,而此编译器在python3中,但我无法理解我的错误
感谢您的帮助
答案 0 :(得分:1)
您只需要使用名称来调用函数,而无需在调用已声明的函数时使用def
。您使用的python版本没有问题。在python2.7
或python3
中,它的工作原理相同。
def guessr(inpt):
guess = input("type something: ")
print(guess)
if type(guess) == str:
print("is a string")
elif type(guess) == int or type(guess) == float:
print("is a number")
else:
print("i don't know")
return()
guessr(67)