gpt4 book ai didi

python - 数学函数python代码检查

转载 作者:太空宇宙 更新时间:2023-11-03 11:19:28 24 4
gpt4 key购买 nike

大家好,我正在学习 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com