寫一個 Python 程序,求三個數的和與均值。這個 Python 示例接受三個整數值,並使用算術運算符計算總和和平均值。
num1 = int(input("Please Enter the First Number = "))
num2 = int(input("Please Enter the Second number = "))
num3 = int(input("Please Enter the Third number = "))
sumOfThree = num1 + num2 + num3
avgOfThree = sumOfThree / 3
print('The sum of {0}, {1} and {2} = {3}'.format(num1,num2, num3, sumOfThree))
print('The Average of {0}, {1} and {2} = {3}'.format(num1,num2, num3, avgOfThree))
Python 程序求三個浮點數的和與均值。
num1 = float(input("Please Enter the First Number = "))
num2 = float(input("Please Enter the Second number = "))
num3 = float(input("Please Enter the Third number = "))
sumOfThree = num1 + num2 + num3
avg = sumOfThree / 3
flooravg = sumOfThree // 3
print('The sum of {0}, {1} and {2} = {3}'.format(num1,num2, num3, sumOfThree))
print('The Average of {0}, {1} and {2} = {3}'.format(num1,num2, num3, avg))
print('Floor Average of {0}, {1} and {2} = {3}'.format(num1,num2, num3, flooravg))
Please Enter the First Number = 19.6
Please Enter the Second number = 12.8
Please Enter the Third number = 156.98
The sum of 19.6, 12.8 and 156.98 = 189.38
The Average of 19.6, 12.8 and 156.98 = 63.126666666666665
Floor Average of 19.6, 12.8 and 156.98 = 63.0
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/233612.html