使用者輸入三個數字,判斷可以構成什麼三角形?

2021-10-05 05:54:55 字數 2180 閱讀 8308

1、練習1:使用python實現兩個數字的交換

a= input(「請輸入乙個數字:」)

b= input(「請在輸入乙個數字:」)

a,b=b,a

print(a,b)

2、練習2:結合邏輯運算子來判斷,使用者輸入乙個年份,判斷這個年份是不是閏年

世紀年:能被400整除的才是閏年(能被100整除的才是世紀年)year%400==0

普通年:能被4整除的才是閏年 year%100!=0 year%4= =0

year=int(input("請輸入乙個年份: "))

if year % 400 = = 0 or year % 4 = = 0 and year % 100 != 0:

print (「閏年」)

else:

print(「平年」)

3、練習3:使用者輸入年齡和婚姻狀況,根據不同的場景,過年回家會得到什麼樣的待遇。

年齡 — 22

婚姻狀況 — 已婚 未婚

年齡小於22,未婚 ----- 有沒有男朋友

年齡小於22,已婚 ----- 婚姻不受法律保護

年齡大於等於22,未婚 ----- 你該結婚了,工作怎麼?收入怎麼?有沒有房?有沒有車?……

年齡大於等於22,已婚 ----- 有沒有孩子呀?要不要老二呀?……

age =int(input("請輸入你的年齡: "))

mar=input("請輸入你的婚姻狀況(未婚,已婚): ")

if age < 22 and mar == 「未婚」:

print(「有沒有男朋友?」)

elif age < 22 and mar = = 「已婚」:

print(「婚姻不受法律保護!」)

elif age >= 22 and mar = = 「未婚」:

print(「你該結婚了,工作怎麼?收入怎麼?有沒有房?有沒有車?……」)

elif age >= 22 and mar = = 「已婚」:

print(「有沒有孩子呀?要不要老二呀?……」)

4、練習4:使用者輸入乙個分數,判斷這個分數是哪個級別

90以上 ---- 優

80~90 ----- 良

70~80 ----- 中

60~70 ----- 差

60以下 ---- 不及格

a = float(input(「請輸入乙個分數」))

if 90 <= a <= 100:

print(「優」)

elif 80 <= a < 90:

print(「良」)

elif 70 <= a < 80:

print(「中」)

elif 60 <= a < 70:

print(「差」)

elif 0 <= a < 60:

print(「不及格」)

else:

print(「請輸入正確的分數,請重新輸入」)

5、練習5:使用者輸入三個數字,判斷可以構成什麼三角形?

a=int(input(「輸入第乙個數:」))

b=int(input(「輸入第二個數:」))

c=int(input(「輸入第三個數:」))

if (a+b>c) and (a+c>b) and (b+c>a):

if a= =b= =c:

print(「等邊三角形」)

elif (a= =b or a= =c or b= =c):

print(「等腰三角形」)

elif (aa+bb= =cc) or (aa+bb==cc) or (aa+bb==c*c):

print(「直角三角形」)

else:

print(「不規則三角形」)

else :

print(「構不成三角形」)

6、使用者輸入兩個值,如果這兩個值都是字母則輸出ok,否則輸出error。

zimu = input(「請輸入乙個字母:」)

zimu1 = input(「請輸在入乙個字母:」)

if (zimu <=『z』 and zimu >= 『a』 or zimu <= 『z』 and zimu >= 『a』) and (zimu1 <=『z』 and zimu1 >= 『a』 or zimu1 <= 『z』 and zimu1 >= 『a』):

print(「ok」)

else:

print(「error」)

判斷輸入的三個資料是否可以構成乙個三角形

using system using system.io namespace 列印軟體說明 獲取可以組成三角形的三個正確的資料 public static void receiveside 定義乙個物件陣列儲存使用者輸入的引數 object obj strtemp.split tochararray...

三個數字比較大小

本題要求將輸入的任意3個整數從小到大輸出。輸入格式 輸入在一行中給出3個整數,其間以空格分隔。輸出格式 在一行中將3個整數從小到大輸出,其間以 相連。相信大家看到這個題目時的第一想法都是,我直接排序就好了。的確,排序是這類問題的通解,任意乙個排序演算法都可以將這道題完美解決。但是博主看到題目中只有三...

python 輸入三個數判斷是什麼三角形

filename function judgment author judy time 2018.9.26 a int input please input the first side 輸入第一條邊 b int input please input the second side 輸入第二條邊 c...