python - python摄氏到华氏转换语法错误

标签 python syntax-error

我写:

def celcius_to_fahrenheit:

fahr = (float(celcius) * 1.8) + 32
return fahr

celcius =input("Enter Degrees Celcius:")
print (celcius_to_fahrenheit)

并得到以下错误:
File ".\025 celcius-to-fahrenheit.py", line 1
def celcius_to_fahrenheit :
                          ^
SyntaxError: invalid syntax

在原子文本阅读器中

最佳答案

您的代码中需要进行一些小的更改:

def celsius_to_fahrenheit(celsius):
      fahr = (float(celsius) * 1.8) + 32
      return fahr

celsius =input("Enter Degrees Celsius:")
print (celsius_to_fahrenheit(celsius))

在python中,请始终记住您的缩进和函数调用,并定义应像这样

关于python - python摄氏到华氏转换语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48378916/

相关文章:

python - 使用 argv 时出错

c# - VB.NET 到 C# 的转换错误

python - 总是需要在 Python 多处理中使用 args 语法吗?

python - 如何使用 nose2 从给定的包中获取覆盖率报告

python - Python网络套接字-[WinError 10053]

python-3.x - 将Python3转换为Python2

c - for循环程序语法错误

python - 如何将带有附加功能的 Python 模块打包为默认值?

python - Huggingface Trainer 抛出 AttributeError :'Namespace' 对象没有属性“get_process_log_level”

sql - Sybase proc 抛出 "Incorrect syntax near ' ='"