異想-天開 python---while、for、if-else 循環學習


for循環:

for i in range(10):  # i循環10次
print('------',i)
for j in range(10):
print(j)
if j > 2 :
break #跳出循環體

while循環:
age_oldboy_guess = 50
conet = 0
# age_guess = int(input('age_oldboy_guess:'))
# if age_oldboy_guess == age_guess:
# print('猜對了!')
# print('get over!') # 這一段已經寫多余了。。
# exit()
# else:
# print('猜錯了!')
while conet < 3 :
# for i in range(3):
age_guess = int(input('age_oldboy_guess:'))
if age_oldboy_guess == age_guess:
print('猜對了!')
break
else:
print('猜錯了!')
conet += 1
# else:
# print("游戲結束!")

if conet == 3:
i = input('還想玩嗎?繼續請輸入Y/y:')
if i == 'Y' or i =='y':
conet = 0
else:
break
print('get over!')

if--else循環:
name = input('name:')
sex = input('sex:')
age = int(input('age:'))

if sex == "f":
if age < 28 :
print("I LOVE girl!")
else:
print('2222!')
else:
print("1111")

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com