新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:檢查三角形是否有效
創(chuàng)新互聯(lián)Python教程:

為略陽等地區(qū)用戶提供了全套網(wǎng)頁設計制作服務,及略陽網(wǎng)站建設行業(yè)解決方案。主營業(yè)務為做網(wǎng)站、網(wǎng)站設計、略陽網(wǎng)站設計,以傳統(tǒng)方式定制建設網(wǎng)站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
編寫一個 Python 程序,使用用戶指定的角度檢查三角形是否有效。記住,任何三角形都是有效的,如果三角形中 3 個角的和等于 180°
檢查三角形是否有效的 Python 程序示例 1
這個 python 程序幫助用戶輸入三角形的所有角度。接下來,我們使用 If Else 語句檢查給定角度之和是否等于 180°。如果為真,print 語句將打印一個有效的三角形。否則, python 程序打印為無效三角形。
# Python Program to check Triangle is Valid or Not
a = int(input('Please Enter the First Angle of a Triangle: '))
b = int(input('Please Enter the Second Angle of a Triangle: '))
c = int(input('Please Enter the Third Angle of a Triangle: '))
# checking Triangle is Valid or Not
total = a + b + c
if total == 180:
print("\nThis is a Valid Triangle")
else:
print("\nThis is an Invalid Triangle")
驗證三角形是否有效的 Python 程序示例 2
在上面的 Python 例子中,我們忘了檢查任何一個角度是否為零。因此,我們使用邏輯與運算符來確保所有角度都大于 0
a = int(input('Please Enter the First Angle of a Triangle: '))
b = int(input('Please Enter the Second Angle of a Triangle: '))
c = int(input('Please Enter the Third Angle of a Triangle: '))
# checking Triangle is Valid or Not
total = a + b + c
if (total == 180 and a != 0 and b != 0 and c != 0):
print("\nThis is a Valid Triangle")
else:
print("\nThis is an Invalid Triangle")
Please Enter the First Angle of a Triangle: 70
Please Enter the Second Angle of a Triangle: 70
Please Enter the Third Angle of a Triangle: 40
This is a Valid Triangle
>>>
=================== RESTART: /Users/suresh/Desktop/simple.py ===================
Please Enter the First Angle of a Triangle: 90
Please Enter the Second Angle of a Triangle: 90
Please Enter the Third Angle of a Triangle: 0
This is an Invalid Triangle
>>> 本文名稱:Python程序:檢查三角形是否有效
文章起源:http://www.dlmjj.cn/article/cceoipo.html


咨詢
建站咨詢
