""" 評分規則: A >=90 B >=80 C >=70 D 其餘 用戶輸入成績,根據成績的不一樣顯示不一樣的級別。 """ # 代碼 score = int(input("請輸入成績:")) if score >= 90: print("A") elif score >= 80: print("B") elif score >= 70: print("C") else: print("其餘")
message = """歡迎致電10086 1.話費查詢; 2.流量服務; 3.業務辦理; 4.人工服務""" print(message) index = int(input('請輸入你要選擇的服務:')) if index==1: print('話費查詢') elif index == 2: print('流量服務') elif index == 3: content = """業務辦理 1. 修改密碼; 2. 更改套餐; 3. 停機;""" print(content) value = int(input('請輸入要辦理的業務:')) if value == 1: print('修改密碼') elif value == 2: print('更改套餐') elif value == 3: print('停機') else:print('錯誤') elif index == 4: print('人工服務') else: print('輸入錯誤')
循環打印「人生苦短,我用python。」python
# 1. 循環打印「人生苦短,我用python。」 """ while True: print("人生苦短,我用python。") """
while後加入條件面試
# 2. while後加入條件 """ while 1 > 0 and 2 > 1: print("人生苦短,我用python。") """
數字相加編碼
# 3. 數字相加 """ count = 1 value = count + 1 print(value) """ """ count = 1 count = count + 1 print(count) """
經過循環,讓count每次加1debug
# 4. 經過循環,讓count每次加1 """ count = 1 while True: print(count) count = count + 1 """ # 練習:此時只打印1 """ while True: count = 1 print(count) count = count + 1 """
請經過循環 1,2,3...10code
# 5. 請經過循環 1,2,3...10 # 靈活使用debug模式,設斷點 """ count = 1 while count <= 10: print(count) count = count + 1 print("結束") """
請經過循環 1,2,3,4,5,6,8,9,10utf-8
# 6. 請經過循環 1,2,3,4,5,6,8,9,10 """ # 錯誤示例:此時執行到7時,條件不知足,循環結束 count = 1 while count <= 10 and count != 7: print(count) count = count + 1 """ """ # 正確示例,經常使用(本身用的) count = 1 while count <= 10: if count != 7: print(count) count = count + 1 """ """ # 另外的方法,麻煩可是是一種思路 count = 1 while count <= 6: print(count) count = count + 1 count = 8 while count <= 10: print(count) count = count + 1 """ """ # 正確示例,另外一種思路,使用了pass count = 1 while count <= 10: if count == 7: pass else: print(count) count = count + 1 """
關鍵字:breakci
# 7. 關鍵字:break """ while True: print(666) break # 終止當前循環 print("結束") """ # 練習 """ # 經過break實現1`10 count = 1 while True: print(count) count = count + 1 if count > 10: break """ """ 另外一種實現,break的條件不一樣 count = 1 while True: print(count) if count == 10: break count = count + 1 """ """ # break是終止當前循環 while True: print("你好") while True: print(666) break break """
關鍵字:continueunicode
# 8. 關鍵字:continue """ count = 1 while count <= 10: print(count) continue # 本次循環若是遇到continue,則再也不往下走,而是回到while條件處 count = count + 1 # 一直打印1 """ """ # 示例:1,2,3,4,5,6,8,9,10 count = 1 while count <= 10: if count == 7: count = count + 1 continue print(count) count = count + 1 """
while else字符串
# 9. while else """ count = 1 while count < 10: print(count) count = count + 1 else: # 再也不知足while後條件時,觸發。或條件 == False print("ELSE代碼塊") print("結束") """ """ count = 1 while True: print(count) if count == 10: break count = count + 1 else: # 再也不知足while後條件時,觸發。或條件 == False print("ELSE代碼塊") # 此時else語句不執行 print("結束") """
while循環總結input
算術運算符
+ - * / ** % // += -= *= /= **= %= //=
int / str / bool 三種類型相互轉換
邏輯運算符
or
第一個值若是轉換成布爾值是True,則value = 第一個值
第一個值若是轉換成布爾值是False,則value = 第二個值
若是有多個or條件,則從左到右依次進行上述流程。
面試題:
value = 1 or 9 print(value) # 打印結果是1
and
not
編碼擴展
單位
8bit = 1byte 1024byte = 1KB 1024KB = 1MB 1024MB = 1GB 1024GB = 1TB 1024TB = 1PB 1024TB = 1EB 1024EB = 1ZB 1024ZB = 1YB 1024YB = 1NB 1024NB = 1DB 常⽤到TB就夠了