Python实例1 计算平方根
#codingutf-8 #filename:test1.py #计算正数平方根 nonefloat(input(输入第一个数字)) ntwonone**0.5 print(%0.3f的平方根是%0.6f%(none,ntwo))运行结果#codingutf-8 #filename:test1.py #计算负数及复数平方根 #导入复数数学模块 import cmath none float(input(请输入一个数字: )) none_sqrt cmath.sqrt(none) print({0} 的平方根为 {1:0.3f}{2:0.3f}j.format(none ,none_sqrt.real,none_sqrt.imag))运行结果