Python程序:计算数字平方
创新互联Python教程:

成都创新互联服务项目包括雨湖网站建设、雨湖网站制作、雨湖网页制作以及雨湖网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,雨湖网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到雨湖省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
写一个 Python 程序,用算术运算符和函数计算一个数的平方,并举例说明。
计算数字平方的 Python 程序
这个 Python 程序允许用户输入任何数值。接下来,Python 使用算术运算符 找到该数字的平方
# Python Program to Calculate Square of a Number
number = float(input(" Please Enter any numeric Value : "))
square = number * number
print("The Square of a Given Number {0} = {1}".format(number, square))数字输出的 Python 平方
Please Enter any numeric Value : 9
The Square of a Given Number 9.0 = 81.0
Python 程序求一个数的平方示例 2
这个 Python 平方的一个数字例子同上。但是,这次我们使用的是指数算子。
number = float(input(" Please Enter any numeric Value : "))
square = number ** 2
print("The Square of a Given Number {0} = {1}".format(number, square))
Please Enter any numeric Value : 10
The Square of a Given Number 10.0 = 100.0
用函数求一个数的平方的 Python 程序
在这个 Python 程序的例子中,我们定义了一个函数,它返回一个数字的平方。
def square(num):
return num * num
number = float(input(" Please Enter any numeric Value : "))
sqre = square(number)
print("The Square of a Given Number {0} = {1}".format(number, sqre)) 分享标题:Python程序:计算数字平方
文章位置:http://www.jxjierui.cn/article/cdccgds.html


咨询
建站咨询
