目錄python
nick handsome, height 180, age 18, weight 140
,切割出字符串內nick的身高、體重、年齡a="nick handsome height 180 age 18 weight 140" print("身高:"+a[-21:-18]) print("年齡:"+a[-13:-11]) print("體重:"+a[-3:])
T = input("輸入體重") if T[-3:] == 'jin': kg = eval(T[:-3])/2 print(str(kg)+'kg') elif T[-2:] == 'MG': kg = eval(T[:-2])/10000 print(str(kg) + 'kg') elif T[-1:] == 'g': kg = eval(T[:-1])/1000 print(str(kg) + 'kg') else : print("輸入錯誤,請從新輸入")
num1=int(input("輸入數")) D=str(input("運算符:")) num2=int(input("輸入數")) if D== '+': s=num1+num2 print(s) elif D =='-' : s=num1-num2 print(s) elif D =='*' : s=num1*num2 print(s) elif D=='/' : s=num1/num2 print(s) else : print("錯了哦,請重新輸入")
age=13 age1=int(input("請輸入年齡:")) if age1 > age : print("猜大了") elif age1 < age : print("猜小了") else : print("哇,你真厲害!!!")