Python程序:求三个数的和与均值

创新互联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

网站栏目:Python程序:求三个数的和与均值
文章源于:http://www.shufengxianlan.com/qtweb/news36/492686.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联