# Enter a code
L = [75, 92, 59, 68, 99]
sum = 0.0
for x in L:
sum = sum + x
print(sum / 5)
L = [75, 92, 59, 68, 99]
sum = 0.0
for x in L:
sum = sum + x
print(sum / 5)
2021-09-14
# Enter a code
a=21
if a>=18:
print('adult')
elif a>= 6:
print('teenager')
elif a>= 3:
print('kid')
else:
print('baby')
a=21
if a>=18:
print('adult')
elif a>= 6:
print('teenager')
elif a>= 3:
print('kid')
else:
print('baby')
2021-09-14
这里,因为score = 59 < 60,所以if的判断是True,因此就会执行print('抱歉,考试不及格')。
这里有几个需要注意的地方:
可以看到print('抱歉,考试不及格')这行代码明显比上一行代码缩进了,这是因为这行代码是if判断的一个子分支,因此需要缩进,在Python规范中,一般使用4个空格作为缩进
在if语句的最后,有一个冒号:,这是条件分支判断的格式,在最后加入冒号:,表示接下来是分支代码块
这里有几个需要注意的地方:
可以看到print('抱歉,考试不及格')这行代码明显比上一行代码缩进了,这是因为这行代码是if判断的一个子分支,因此需要缩进,在Python规范中,一般使用4个空格作为缩进
在if语句的最后,有一个冒号:,这是条件分支判断的格式,在最后加入冒号:,表示接下来是分支代码块
2021-09-14
a='hello world'
b='hello world'
c='hello world'
print(a)
print(b)
print(c)
b='hello world'
c='hello world'
print(a)
print(b)
print(c)
2021-09-14
# Enter a code
a=3.1415926
b='learn python in imooc'
c=100
d=0b1101
print isinstance(a,float)
print isinstance(b,str)
print isinstance(c,int)
print isinstance(d,int)
a=3.1415926
b='learn python in imooc'
c=100
d=0b1101
print isinstance(a,float)
print isinstance(b,str)
print isinstance(c,int)
print isinstance(d,int)
2021-09-14
# coding: utf-8
a='zhe shi zhong guo'
b='这是中国'
c='"这是一句中英文混合的Python字符串:Hello World!"'
print(a)
print(b)
print(c)
a='zhe shi zhong guo'
b='这是中国'
c='"这是一句中英文混合的Python字符串:Hello World!"'
print(a)
print(b)
print(c)
2021-09-14
# Enter a code
a='Life is short,{}'
b='you need Python.'
result=a.format(b)
print(result)
a='Life is short,{c}'
b='you need Python.'
result=a.format(c=b)
print(result)
a='Life is short,{}'
b='you need Python.'
result=a.format(b)
print(result)
a='Life is short,{c}'
b='you need Python.'
result=a.format(c=b)
print(result)
2021-09-13
# Enter a code
a='Life is short,{}'
b='you need Python.'
result=a.format(b)
print(b)
a='Life is short,{c}'
b='you need Python.'
result=a.format(c=b)
print(result)
a='Life is short,{}'
b='you need Python.'
result=a.format(b)
print(b)
a='Life is short,{c}'
b='you need Python.'
result=a.format(c=b)
print(result)
2021-09-13
# Enter a code
a=r''' '\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer. '''
print(a)
a=r''' '\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer. '''
print(a)
2021-09-13
我觉得没必要判断奇偶啊,直接num=0 每次加2就可以了。
num = 0
sum = 0
while True:
if num > 1000:
break
sum = sum + num
num = num + 2
print(sum)
num = 0
sum = 0
while True:
if num > 1000:
break
sum = sum + num
num = num + 2
print(sum)
2021-09-12
#..........
ab= ' {}'
b =ab.format('Life is short,you need python')
print(b)
N = 'Life is {0},you need {1}'
b2= N.format('short','python')
print(b2)
N2 ='Life is {w},you need {y}'
short ='short'
python ='pythin'
b3=N2.format(w=short,y=python)
print(b3)
ab= ' {}'
b =ab.format('Life is short,you need python')
print(b)
N = 'Life is {0},you need {1}'
b2= N.format('short','python')
print(b2)
N2 ='Life is {w},you need {y}'
short ='short'
python ='pythin'
b3=N2.format(w=short,y=python)
print(b3)
2021-09-10
moban='{a} {b} {c},{d} {e} {f}.'
a1='Life'
b1='is'
c1='short'
d1='you'
e1='need'
f1='Python'
result=moban.format(a=a1,b=b1,c=c1,d=d1,e=e1,f=f1)
print(result)
a1='Life'
b1='is'
c1='short'
d1='you'
e1='need'
f1='Python'
result=moban.format(a=a1,b=b1,c=c1,d=d1,e=e1,f=f1)
print(result)
2021-09-09
num=0
L = ['Alice', 66, 'Bob', True, 'False', 100]
while num<=5:
num=num+1
if num%2==0:
continue
print(L[num])
L = ['Alice', 66, 'Bob', True, 'False', 100]
while num<=5:
num=num+1
if num%2==0:
continue
print(L[num])
2021-09-08