循环

# l = []
# for x in range(3,10):
# #pass
# l.append(x)
# print(x,':',l)
# print(l)

#break/continue(break:终止。continue:继续)
#list = [1,2,3,4] #遍历
# for x in list:
# if x == 3:
# print(x,'#'*20)
# break #终止当前循环
# else:
# print('break:', x)
# print('*'*100)

# for x in list:
# print('第%d轮循环'% x)
# if x != 3:
# print(x)
# continue
# elif x == 3:
# break
# else:
# print('contrnue',x)

#while循环 当...时候
sum = 0
n = 9
while n > 0:
sum = sum + n
print('sum--》', sum)
if sum>20:
break
n = n - 2
print('n--》',n)
'''
打印三角形

*
* *
* * *
* * * *
* * * * *

'''
for i in range(10):
for j in range(10 - i, 10):
print(end=" ")
for k in range(0, 10-i):
print("*", end=" ")
print("")




a = '您是一个老年人'
b = '您是一个中年人'
c = '您是一个成年人'
d = '您是祖国的花朵和未来'
e = '输入有误请重新输入'
count = 0
while count < 5:
age = input('请输入年龄>>>:')
if int(age)>=65:
print(a)
count +=1
con = input('是否继续输入(yes/no)')
if con == 'yes':
continue
else:
break
elif 65>int(age)>=45:
print(b)
count += 1
con = input('是否继续输入(yes/no)')
if con == 'yes':
continue
else:
break
elif 45>int(age) >= 18:
print(c)
count += 1
con = input('是否继续输入(yes/no)')
if con == 'yes':
continue
else:
break
elif 18>int(age) >0:
print(d)
count += 1
con = input('是否继续输入(yes/no)')
if con == 'yes':
continue
else:
break
else:
print(e)
count += 1
con = input('是否继续输入(yes/no)')
if con == 'yes':
continue
else:
break
posted @ 2018-05-21 17:34  老僧观天下  阅读(151)  评论(0编辑  收藏  举报