标签:htm .com print 用途 nbsp www blog 死循环 流程控制
流程控制
一:if语句
age = int(input("请输入年龄:"))
sex = input("请输入性别:")
if sex == ‘falme‘and age < 30:
print("俺很中意你!")
else:
print("滚!")
OLDBOY_AGE=56
age=input(‘猜一猜年龄:‘)
age=int(age)
if age>OLDBOY_AGE:
print(‘太大了!‘)
elif age<OLDBOY_AGE:
print(‘太小了!‘)
else:
print(‘猜对了‘)
#! usr/bin/env python
# -*- coding: utf-8 -*-
score=input("请输入学生成绩:")
score=int (score)
if score>=90:
print(‘A‘)
elif score>=80:
print(‘B‘)
elif score>=70:
print(‘C‘)
elif score>=70:
print(‘D‘)
elif score>=60:
print(‘E‘)
else:
print(‘F‘)
Whol循环
ount=0
while count<10:
print(count)
count+=1
while True: 死循环有特殊用途
print(‘ok‘)
break跳出本层循环
OLDBOY_AGE=56
while 1:
age=input(‘猜一猜年龄:‘)
age=int(age)
if age>OLDBOY_AGE:
print(‘太大了!‘)
elif age<OLDBOY_AGE:
print(‘太小了!‘)
else:
print(‘猜对了‘)
continue跳出本次循环
cont = 0
while cont < 10:
if cont >=4 and cont<=6:
cont+=1
continue
print(cont)
cont+=1
标签:htm .com print 用途 nbsp www blog 死循环 流程控制
原文地址:http://www.cnblogs.com/w-s-l123/p/7214324.html