当前分类:300例题>>正文

Python示例:求三个数的和与均值

来源:互联网   更新时间:2023年6月18日  

Python 示例

写一个 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://6yhj.com/leku-p-4291.html  版权所有,转载请保留本地址!
[猜你喜欢]

标签: 正则表达式