python - 数学函数python代码检查

标签 python

大家好,我正在学习 Python 类(class),到目前为止很喜欢它并且无法停止练习。我有我认为练习要求的东西。我的一个问题是我从哪里开始列出变量,如总和、差、乘积等。我使用的是 Sublime Text,除了 sum 之外它们都是白色的,这是为什么?即使我运行时代码数字看起来是准确的,这是否会把事情搞砸?

''' Write a program that prompts the user for two integers and then prints 
'''sum, difference, product, average, distance, max and min.

import math
number1 = float(input("Please enter an integer: "))
number2 = float(input("Please enter another integer: "))
print()
print()
sum = number1 + number2
difference = number1 - number2
product = number1 * number2
average = (number1 + number2) / 2
distance = abs(number1 - number2)
maximum = max(number1, number2)
minimum = min(number1, number2)

print("Sum between the two:",sum)
print("Difference between the two:",difference)
print("Product between the two:",product)
print("Average between the two:",average)
print("The distance between the two:",distance)
print("The maximum between the two:",maximum)
print("The minimum between the two:",minimum)

感谢您的宝贵时间。

最佳答案

sum 在您的文本编辑器中出现的事实是 it is a function name以及。因此,如果您希望稍后在代码中使用此函数,它会引发异常。

对您的代码的几点说明:

如果您不使用它,则无需import math

''' 标记注释的开始和结束。要注释掉一行,请使用 #。您在开头的评论应该是:

'''this is a multiline comment
and here it continues'''

# this is a single line comment

关于python - 数学函数python代码检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45931052/

相关文章:

python - 透视 Pandas 数据并添加列

python - 从 Tensorflow 中的自定义图像数据集创建批处理

python - bool 和 list 格式字符串的参数不足

python - 在 Python 中导入音轨(wav 或 aiff)

python - 填充 Postgres 数据库时为 "stdin is not a tty"

python - 如何将 "step"传递给 GradientTape 中的 ExponentialDecay

python - 无法对我的数据应用 scipy.signal lfilter

python - 尝试使用 mod_wsgi 设置 flask

python - Django 1.4 可以提供媒体文件服务,但不是静态的

python - 我可以在 Python 中生成每行等于 1 的随机矩阵值(小数)吗?