寫一個 Python 程序,求兩個數的平均值。這個 Python 示例接受兩個整數,並計算總和和平均值。
x = int(input("Please Enter the First Number = "))
y = int(input("Please Enter the Second number = "))
sumOfTwo = x + y
avgOfTwo = sumOfTwo / 2
flooravgofTwo = sumOfTwo // 2
print('The sum of {0} and {1} = {2}'.format(x, y, sumOfTwo))
print('The Average of {0} and {1} = {2}'.format(x, y, avgOfTwo))
print('Floor Average of {0} and {1} = {2}'.format(x, y, flooravgofTwo))
Python 程序求兩個浮點數的平均值。
x = float(input("Please Enter the First Number = "))
y = float(input("Please Enter the Second number = "))
sumOfTwo = x + y
avgOfTwo = sumOfTwo / 2
flooravgofTwo = sumOfTwo // 2
print('The sum of {0} and {1} = {2}'.format(x, y, sumOfTwo))
print('The Average of {0} and {1} = {2}'.format(x, y, avgOfTwo))
print('Floor Average of {0} and {1} = {2}'.format(x, y, flooravgofTwo))
Please Enter the First Number = 22.9
Please Enter the Second number = 14.7
The sum of 22.9 and 14.7 = 37.599999999999994
The Average of 22.9 and 14.7 = 18.799999999999997
Floor Average of 22.9 and 14.7 = 18.0
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/238737.html