# 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,因此就會執(zhí)行print('抱歉,考試不及格')。
這里有幾個需要注意的地方:
可以看到print('抱歉,考試不及格')這行代碼明顯比上一行代碼縮進(jìn)了,這是因為這行代碼是if判斷的一個子分支,因此需要縮進(jìn),在Python規(guī)范中,一般使用4個空格作為縮進(jìn)
在if語句的最后,有一個冒號:,這是條件分支判斷的格式,在最后加入冒號:,表示接下來是分支代碼塊
這里有幾個需要注意的地方:
可以看到print('抱歉,考試不及格')這行代碼明顯比上一行代碼縮進(jìn)了,這是因為這行代碼是if判斷的一個子分支,因此需要縮進(jìn),在Python規(guī)范中,一般使用4個空格作為縮進(jìn)
在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