分支結構基本語法javascript
if 條件表達式: 語句1 語句2 語句3 ......
# if 語句聯繫一
# 若是大家都買個人習題課,我就發財了
a = " "
# 字符串的真假:
#只有空字符串(長度爲0的字符串)爲False,其他全爲True
#a = "都買習題課"
if a:
print("我就發財了")
print("迎娶王曉靜")
print("日子還得過啊")
# if 聯繫二
age = 19
if age > 16:
print("喝酒去")
print("下次你請我")
語法結構:css
if 條件表達式: 語句1 語句2 else 語句1 語句2
a = ""
# 字符串的真假:
#只有空字符串(長度爲0的字符串)爲False,其他全爲True
#a = "都買習題課"
if a:
print("我就發財了")
print("迎娶王曉靜")
else:
print("繼續吃土吧")
print("跟五姑娘繼續耗下去吧")
print("日子還得過啊")
# input的做用是
# 1. 在屏幕上輸出括號內的字符串
# 2. 接受用戶輸入的內容並返回到程序
# 3. input返回的內容必定是字符串類型
# input負責接受用戶輸入並把內容返回給變量
gender = input("請輸入您的性別")
# 打印輸入的內容
print(gender)
if gender == "man":
print("走,喝酒抽菸剃頭")
print("一塊兒玩去呀")
else:
print("你究竟是個啥子呀")
print("對不起,我是男生")
# 考試成績判斷
# 成績由用戶輸入d
# 90分以上:輸出優秀
# 80-90 :良
# 70-80 :中
# 60-70 :平
# 60一下:輸出:我沒你這撒學僧
# 輸入成績,須要用到input函數
# input輸入的值所有是字符串類型
score = input("輸入成績")
# 解決輸入是字符串的問題
score = int(score)
if score >=90:
print("優秀")
if score >=80 and score <90:
print("良")
if score >=70 and score <80:
print("中")
if score >=60 and score <70:
print("平")
if score <60:
print("我沒你這撒學僧")
# scroe 存放學生成績
# 注意input的返回值的類型
score = input("請輸入學生的成績:")
# 須要把str轉換成int
score = int(score)
if score>=90:
print("A")
elif score >=80:
print("B")
elif score >=70:
print("C")
elif score >=60:
print("D")
else:
print("我沒你這樣學生")