新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python 程序:使用底部和高度計(jì)算三角形面積
創(chuàng)新互聯(lián)python教程:

為玉門等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及玉門網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站設(shè)計(jì)、玉門網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
用一個(gè)實(shí)際例子編寫 Python 程序,用底和高來求三角形的面積。
使用底部和高度查找三角形面積的 Python 程序示例 1
這個(gè) Python 程序允許用戶輸入三角形的底部和高度。通過使用底部和高度值,它可以找到三角形的面積。用底和高求三角形面積的數(shù)學(xué)公式:面積=(底*高)/ 2。
# Python Program to find Area of a Triangle using base and height
base = float(input('Please Enter the Base of a Triangle: '))
height = float(input('Please Enter the Height of a Triangle: '))
# calculate the area
area = (base * height) / 2
print("The Area of a Triangle using", base, "and", height, " = ", area)使用底部和高度計(jì)算三角形面積的 Python 程序示例 2
這個(gè) Python 程序?qū)τ谌切蔚拿娣e和上面一樣。然而,我們使用 Python 函數(shù)概念分離了三角形的面積程序邏輯。
# Python Program to find Area of a Triangle using base and height
def area_of_triangle(base, height):
return (base * height) / 2
base = float(input('Please Enter the Base of a Triangle: '))
height = float(input('Please Enter the Height of a Triangle: '))
# calculate the area
area = area_of_triangle(base, height)
print("The Area of a Triangle using", base, "and", height, " = ", area)使用底部和高度輸出的三角形的 Python 面積
Please Enter the Base of a Triangle: 35
Please Enter the Height of a Triangle: 85
The Area of a Triangle using 35.0 and 85.0 = 1487.5 網(wǎng)站標(biāo)題:Python 程序:使用底部和高度計(jì)算三角形面積
URL標(biāo)題:http://www.dlmjj.cn/article/cocegcs.html


咨詢
建站咨詢
