9月 232020
 
#自定义函数,a*a+b*b=c*c,开平方求c值
def Pythagorean_theorem(a,b):
    return 'The right triangle third side\'s length is {}'.format((a**2 + b**2)**(1/2))
#引号内的字符串出现符号时需要使用\转义
#使用.format()将格式化的运算值填入字符串中

#调用函数,传入参数并打印函数返回
print(Pythagorean_theorem(3,4))
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python38/python.exe c:/Users/harveymei/hello.py
The right triangle third side's length is 5.0
PS C:\Users\harveymei> 

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据