Python-在请求时返回应该可以工作的语法错误
我正在做一个小程序,以创建一个有效的计算器。到目前为止,程序还不错,但我在尝试在函数中设置变量时遇到了这个问题Python-在请求时返回应该可以工作的语法错误,python,Python,我正在做一个小程序,以创建一个有效的计算器。到目前为止,程序还不错,但我在尝试在函数中设置变量时遇到了这个问题 def request( val1 = int(input('Enter the first value: ')) operation1 = (input('''Enter the operation: ''')) val2 = int(input('Enter the second value: ')) ) 由于某些原因,只有第三行(操作1)有错误。不确定python是
def request(
val1 = int(input('Enter the first value: '))
operation1 = (input('''Enter the operation: '''))
val2 = int(input('Enter the second value: '))
)
由于某些原因,只有第三行(操作1)有错误。不确定python是否愚蠢或者我做错了什么我相信python中的函数语法是:
def fxnName(args_if_any):
val1 = int(input('Enter the first value: '))
...
您正在为一个函数包装参数空间中的所有行。Python具有非常严格的函数语法,这与其他不需要空格的编程语言不同。此外,您使用的语法不正确,因为您使用“()”来定义函数的外部限制。函数的正确版本为: 注意“:”然后是缩进。如果删除缩进,它将不会运行。如果你不使用“:”它将不起作用
def request():
val1 = int(input('Enter the first value: '))
operation1 = (input('''Enter the operation: '''))
val2 = int(input('Enter the second value: '))
request()
在
(输入(''输入操作:'')
中,外括号没有多大意义。def请求(……)
完全错误。不要将实际代码放入函数声明中。只有参数和默认值。您需要回到这里,因为您的语法非常非常离谱。def functionname(..)
语法需要一组逗号分隔的参数名,可以选择使用默认值和注释。您的代码缺少逗号,我非常怀疑您是否希望input()
调用为参数提供默认值。请注意,“有错误”和“遇到问题”对问题的描述不是特别好。