學(xué)習(xí)python第一天

1.0 if 判斷

if  4 > 5:
  print('我請(qǐng)你喝酒')
else:
  print('我請(qǐng)你吃飯')

多級(jí)判斷

num = input('請(qǐng)輸入你猜的數(shù)字: ')
#input 輸入的是字符串,所以數(shù)字要要加''
if  num == '1':
  print('一起抽煙')
elif num == '2':
  print('一起喝酒')
elif num == '3':
  print('一起吃飯')
else:
  print('各回各家')

案例3

score = int(input("請(qǐng)輸入分?jǐn)?shù):"))
if score > 100:
  print("我擦,最高才100.。。")
elif score >= 90:
  print("A")
elif score >= 80:
  print("B")
elif score >= 60:
  print('C')
elif score >= 40:
  print('D')
else:
  print('太笨了')

2.0 while 循環(huán)的應(yīng)用

案例一打印1~100

count = 1
flag = True                #滿(mǎn)足條件,執(zhí)行循環(huán)
while flag:
    print(count)
    count = count + 1
    if   count  > 100:
           flag = False     #False 退出循環(huán)
第二種方法
count = 1
while count  <= 100:            #在循環(huán)的時(shí)候就指定條件
        print(count)
        count =  count + 1
案例二打印1+2+3~+100
count = 1
sum = 0
while count <= 100:
      sum = sum + count
      count = count + 1
print(sum)

3.0跳出循環(huán)---------------break

count = 1
while True:
    print(count)
    count = count + 1 
    if count > 200:
        break     #當(dāng)count > 200時(shí)跳出循環(huán)
利用 break 打印1~100
count = 1 
while True:
     print(count)
     count =  count + 1
     if count > 100:
          break

4.0 結(jié)束本次循環(huán),開(kāi)始下次循環(huán)---------------continue

print(111)
count = 1
while count < 20:
  print(count)
  continue
  count = count + 1

案例一:打印1,2,3,4,5,6,8,9,10

count = 0
while  count <= 9:
    count = count + 1
    if  count == 7:
        continue
    print(count)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容