# Enter a code
#coding:utf-8
age=21
if age>=18:
print('adult')
elif age>=6:
print('tennager')
elif age>=3:
print('kid')
else:
print('adult')
#coding:utf-8
age=21
if age>=18:
print('adult')
elif age>=6:
print('tennager')
elif age>=3:
print('kid')
else:
print('adult')
2021-09-15
# Enter a code
#coding:utf-8
age=19
if age>=18:
print('adult')
else:
print('teenager')
#coding:utf-8
age=19
if age>=18:
print('adult')
else:
print('teenager')
2021-09-15
# Enter a code
# coding:utf-8
age=19
if age>=18:
print('adult')
# coding:utf-8
age=19
if age>=18:
print('adult')
2021-09-15
# coding: utf-8
s1 = '这是中文字符串'
s2 = 'this is an English string'
print(s1+s2)
s1 = '这是中文字符串'
s2 = 'this is an English string'
print(s1+s2)
2021-09-15
# Enter a code
# -*- coding: UTF-8 -*-
template='Life is {0},you need {1}'
result=template.format('short','python')
print(result)
print('life is short,you need{}'.format('python'))
print('life is short,you need{launguage}'.format(launguage='python'))
# -*- coding: UTF-8 -*-
template='Life is {0},you need {1}'
result=template.format('short','python')
print(result)
print('life is short,you need{}'.format('python'))
print('life is short,you need{launguage}'.format(launguage='python'))
2021-09-15
# 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