新聞中心
創(chuàng)新互聯(lián)Python教程:

為略陽(yáng)等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及略陽(yáng)網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為做網(wǎng)站、網(wǎng)站設(shè)計(jì)、略陽(yáng)網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
編寫一個(gè) Python 程序,使用用戶指定的角度檢查三角形是否有效。記住,任何三角形都是有效的,如果三角形中 3 個(gè)角的和等于 180°
檢查三角形是否有效的 Python 程序示例 1
這個(gè) python 程序幫助用戶輸入三角形的所有角度。接下來(lái),我們使用 If Else 語(yǔ)句檢查給定角度之和是否等于 180°。如果為真,print 語(yǔ)句將打印一個(gè)有效的三角形。否則, python 程序打印為無(wú)效三角形。
# 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")
驗(yàn)證三角形是否有效的 Python 程序示例 2
在上面的 Python 例子中,我們忘了檢查任何一個(gè)角度是否為零。因此,我們使用邏輯與運(yùn)算符來(lái)確保所有角度都大于 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://fisionsoft.com.cn/article/cceoipo.html


咨詢
建站咨詢
