嘿所有我在蟒蛇课的介绍,到目前为止享受它,不能停止练习。我有我认为练习要求的东西。我有一个问题是我开始列出sum,difference,product等变量。我使用Sublime Text,除了总和,它们都是白色的,为什么呢?即使我运行代码数字似乎是准确的,这会不会搞砸事情?
''' 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)
感谢您的时间。
答案 0 :(得分:2)
sum
在您的文本编辑器中出现的事实也是it is a function name。因此,如果您希望稍后在代码中使用此函数,则会引发异常。
您的代码的几个注释:
如果您不使用它,则无需import math
。
'''
标记了评论的开头和结尾。要注释掉一行,请使用#
。您在开头的评论应该是:
'''this is a multiline comment
and here it continues'''
# this is a single line comment