嘿所有即時通訊的Python入門介紹,到目前爲止享受它,不能停止練習。我有我認爲這個練習所要求的。我有一個問題,就是我開始列出諸如總和,差異,產品等變量。我使用Sublime Text,除了總和之外他們都是白色的,爲什麼?即使當我運行代碼數字似乎是準確的,這是否會與事情混淆?數學函數python代碼檢查
''' 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'是Python中的內置功能,如果你需要使用它未來 – PRMoureu
你會收到一個'TypeError'某處的路線,你應該改變這個名字,如果你當您的自定義變量覆蓋它時,決定使用內置的'sum'函數。 –
啊好吧,這很有道理。代碼本身如何?距離,最大和最小看起來好嗎? – Matticus