1,,if 和elif一个间的区别:
当用if语句时,第一个IF语句运行后会继续运行下一个if语句,要等所有的运行完才行。
而elif语句,只要前面一个达到条件,后面的elif就都不会运行。
int语句:只有字符串全是数字才能运行,当字符串中有字母时,系统就会报错
# while 条件:
# 循环体的代码1
# 循环体的代码2
# 循环体的代码3
# count=0
# while count < 10:
# print(count)
# count+=1
# while True: #死循环
# print(‘ok‘)
# while 1: #死循环
# print(‘ok‘)
#break:跳出本层循环
# count=0
# while count < 10:
# if count == 5:
# break
# print(count)
# count+=1
#continue:跳出本次循环
#0 1 2 3 7 8 9
# count=0
# while count < 10:
# if count >=4 and count <=6:
# count += 1
# continue
# print(count)
# count+=1
# OLDBOY_AGE=56
# while 1:
# age=input(‘猜一猜年龄>>: ‘)
# age=int(age)
#
# if age > OLDBOY_AGE:
# print(‘太大了‘)
# elif age < OLDBOY_AGE:
# print(‘太小了‘)
# else:
# print(‘猜对了‘)
# break
# OLDBOY_AGE=56
# count=1
# while count <= 3:
# age=input(‘猜一猜年龄>>: ‘)
# age=int(age)
#
# if age > OLDBOY_AGE:
# print(‘太大了‘)
# count+=1
# elif age < OLDBOY_AGE:
# print(‘太小了‘)
# count+=1
# else:
# print(‘猜对了‘)
# break
OLDBOY_AGE=56
count=1
while True:
if count > 3:
print(‘您猜的次数超过限制‘)
break
age=input(‘猜一猜年龄>>: ‘)
age=int(age)
if age > OLDBOY_AGE:
print(‘太大了‘)
elif age < OLDBOY_AGE:
print(‘太小了‘)
else:
print(‘猜对了‘)
break
count += 1
# OLDBOY_AGE=56
# while True:
# score = input(‘>>: ‘)
# score = int(score)
#
# if score >= 90:
# print(‘A‘)
# if score >= 80:
# print(‘B‘)
# if score >= 70:
# print(‘C‘)
# if score >= 60:
# print(‘D‘)
# if score < 60:
# print(‘E‘)
OLDBOY_AGE=56
count=0
while True:
if count > 2:
break
age=input(‘猜一猜年龄>>: ‘)
age=int(age)
if age > OLDBOY_AGE:
print(‘太大了‘)
if age < OLDBOY_AGE:
print(‘太小了‘)
if age == OLDBOY_AGE:
print(‘猜对了‘)
break
count += 1
1,,,,while(数字到5跳出循环)
n=0
while True:
if n==5
print(‘you are good‘)
break
n+=1
2.
score=input(‘>>: ‘)
score=int(score)
if score >= 90:
print(‘A‘)
elif score >=80:
print(‘B‘)
elif score >=70:
print(‘C‘)
elif score >=60:
print(‘D‘)
else:
print(‘E‘)
print(‘====>‘)
8.。
逻辑或or
# age=int(input(‘您芳龄几何>>: ‘))
# sex=input(‘您的性别是>>: ‘)
#
# print(sex == ‘female‘ or age > 50 )
# print(False and True or True)
# print((False and True) or True)
# print(False and (True or True))
# #
#
# print(False or False and True)
# print(False or (False and True))
# print(False or True and True)
#
#
print(False or True and False or True)
print(False or ((True and False) or True))
# print(1 > 10 or ( (2 > 1 and 1 < -1) or 4 > 3))
# print(False or True)
---恢复内容结束---
原文:http://www.cnblogs.com/52forjie/p/7203262.html