2021-01-22

a = input(“请输入一个小于10的数字:”)
if int(a)<10:
print(a)
else:print(“数字大于10了!”)

b = []
if not b:
print(“空的列表是false”)

c = “False” #非空字符串也是:false
if c:
print©

d = 10
if d:
print(‘d’)

if 3<d<100:
print(“3<d<100”)

#测试三元条件运算符
num = input(‘请输入数字:’)
print(‘这个数小于10’ if int(num)<10 else ‘这个数不小于10’)

#多分支if,elif,else
score = int(input(‘请输入您的成绩:’))
great = ‘’
if score<60:
great=‘不及格’
elif score<80:
great =‘及格’
elif score<90:
great =‘良好’
elif score<=100:
great =‘优秀’
print(‘您的成绩为{0},等级为{1}’.format(score,great))

print(’**********************************************’)

if score<60:
great=‘不及格’
if 60<=score<80:
great=‘及格’
if 80<=score<90:
great=‘良好’
if score>90:
great=‘优秀’
print(‘您的成绩为{0},等级为{1}’.format(score,great))

#while循环
num = 0
while num<=10:
print(num,end=’\t’)
num += 1

print(’****************************’)

a = 0
sum_all = 0 #所有的数累加和
sum_ou = 0 #所有的偶数累加和
sum_ji =0 #所有的奇数累加和
while a<=100:
sum_all = sum_all + a
if a%2==0:sum_ou += a
else:sum_ji += a
a += 1
print(‘1-100所有数的累加和为:’,sum_all)
print(‘1-100所有数的偶累加和为:’,sum_ou)
print(‘1-100所有数的奇累加和为:’,sum_ji)

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页