日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python-流程控制之循环

發布時間:2024/4/17 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python-流程控制之循环 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
# 1. while循環:條件循環
# I:基本語法
# while 條件:
# 代碼1
# 代碼2
# 代碼3
# ...

# 示范
# name_of_bk='huangdong'
# paw_of_bk='123'
#
# tag=True
# while tag:
# inp_name=input('your name>>:')
# inp_pwd=input('your password>>:')
# if inp_name == name_of_bk and inp_pwd == paw_of_bk:
# print('login successful')
# tag=False
# else:
# print('username or password error')
#
# print('emmmmmm')

# II: while+break:break代表結束本層循環
# 示范:
# while True:
# print(1)
# break
# print(2)
# print(3)

# name_of_bk='huangdong'
# paw_of_bk='123'
#
# while True:
# inp_name=input('your name>>:')
# inp_pwd=input('your password>>:')
# if inp_name == name_of_bk and inp_pwd == paw_of_bk:
# print('login successful')
# break
# else:
# print('username or password error')
#
# print('emmmmmm')

# III: while + continue: continue代表結束本次循環,直接進入下一次
# 示范
# count=1
# while count <6:
# if count == 3:
# count+=1
# continue
# print(count)
# count+1

# 輸錯三次退出
# name_of_bk='huangdong'
# paw_of_bk='123'
#
# count=0
# while True:
# if count == 3:
# print('輸錯次數過多..')
# break
# inp_name=input('your name>>:')
# inp_pwd=input('your password>>:')
# if inp_name == name_of_bk and inp_pwd == paw_of_bk:
# print('login successful')
# break
# else:
# print('username or password error')
# count+=1 #count=3 輸錯3次
#
#
# print('emmmmmm')

# IV:while + else
# count=0
# while True:
# if count == 10:
# break
# print(count)
# count+=1
# else:
# print('else的子代碼塊只有在while循壞沒有被break打斷的情況下才會執行')

# count=0
# while count <= 10:
# print(count)
# count+=1
#
# else:
# print('else的子代碼塊只有在while循壞沒有被break打斷的情況下才會執行')


name_of_bk='huangdong'
pwd_of_bk='123'
count=0
tag=True
while tag:
if count == 3:
print('輸錯次數過多...')
break
inp_name=input('your name>>:')
inp_paw=input('your password>>:')
if inp_name == name_of_bk and inp_paw == inp_paw:
print('login password')
while tag:
print('''
0 退出
1 購物
2 支付
3 查看購物車
''')
cmd=input('>>:')
if cmd == '0':
tag=False
continue
if cmd == '1':
print('購物...')
elif cmd =='2':
print('支付..')
elif cmd == '3':
print('購物車')
else:
print('輸入錯誤的指令')

else:
print('username or password error')

轉載于:https://www.cnblogs.com/huangdong-/p/9989643.html

總結

以上是生活随笔為你收集整理的Python-流程控制之循环的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。