def作为无效语法出现

时间:2018-04-05 18:58:47

标签: python

我在python中定义变量时遇到问题,我目前是初学者,我想对此有所帮助:

def tempc_f():
   C = input("Give me a temp in Celcius and I'll convert it to Fahrenheit: ")
   F = float(9)/float(5)*float(C) + float(32)
   print(str(C),"Degrees Celcius in Fahrenheit is",str(F))   
def tempf_c():
   F1 = input("Give me a temp in Fahrenheit and i'll convert it to Celcius: ")
    C1 = float(F1)-float(32)*float(9)/float(5)
    print(str(F1),"Degrees Fahrenheit in Celcius is",str(C1))
def tempf_k():
   F2 = input("Give me a temp in Fahrenheit and i'll convert it to Kelvin: ")
    K2 = (float(F2)-float(32)/float(1.8)+float(273.15)
def tempc_k()
    C2 = input("Give me a temp in Celcius and I'll convert it to Kelvin: ")
    K3 = float(C2+273.15)
    print(str(C2),"Degrees Celcius in Fahrenheit is",str(K3))
def tempk_c():
    K4 = input("Give me a temp in Kelvin and I'll convert it to Celcius: ")
    C3 = float(K4)-float(273)
    print(str(K4),"Degrees Kelvin in Celcius is",str(C3))

每当我尝试运行此代码时,都会出现错误信息......

file: 'file:///Users/student/Desktop/Zach%27s%20programs/tututu.py'
severity: 'Error'
message: 'E0001:invalid syntax (<string>, line 2)'
at: '2,1'
source: 'pylint'
code: 'E0001'

它说我的def是未定义的,出了什么问题?

1 个答案:

答案 0 :(得分:1)

问题在于:

def tempc_k()
    C2 = input("Give me a temp in Celcius and I'll convert it to Kelvin: ")
    K3 = float(C2+273.15)
    print(str(C2),"Degrees Celcius in Fahrenheit is",str(K3))

您在函数名称末尾缺少冒号