Python基础(2)

Python基础二:

for循环:

for i in  range(0,10,2):

  prin(i)

else:

  print(“结束!!”)

for循环正常结束,执行else语句,否则不执行。

if语句:

age_of_oldboy=56
guess_age=int(input("guess age:"))
if guess_age==age_of_oldboy:
print("Yes,you got it.")
elif guess_age > age_of_oldboy:
print("Think smaller...")
else:
print("Think bigger!")

循环套循环:
for i in range(10):
print("---------",i)
for j in range(10):
print(j)
if j > 5:
break
#break结束整个循环。
continue:
for i in range(10):
if i < 5:
print(i)
else:
continue
print("hehe")

猜名字:
# Author:GaoYuCai
count=0
age_of_oldboy=56
while count <3:
guess_age=int(input("guess age:"))
if guess_age== age_of_oldboy:
print("Yes,you are right!")
break
elif guess_age< age_of_oldboy:
print("Think smaller!")
else:
print("think biggest!")
count=count+1
if count==3:
sw=input("Do you want continue? y/n:")
if sw=="y":
count=0
else:
break


posted @ 2018-12-19 14:47  神奇小秀才  阅读(227)  评论(0编辑  收藏  举报