已采纳回答 / 粗实而夜雨
首先你得理解%的含义,这是取模(取余数)操作,1%2=2;用 num % 2 != 0作为条件也就是余数等于1,题目中要求的是取偶数位置的数据,而列表list的第一位是0,第二个位置是1,以此类推。
2021-01-10
a = 'python' , a为True。print('hello,', a or 'world') 或计算中字串符结果是False,所以显示结果为a=‘python’。b = '',b是空值,print('hello,', b or 'world'),或计算中不显示空值,是以结果显示为world。
2021-01-10
def sub_sum(L):
sum1=0
sum2=0
for a in L:
if a%2==0:
sum1=sum1+a
else:
sum2=sum2+a
return sum1,sum2
L=[1,2,3,4]
b=sub_sum(L)
print(b)
sum1=0
sum2=0
for a in L:
if a%2==0:
sum1=sum1+a
else:
sum2=sum2+a
return sum1,sum2
L=[1,2,3,4]
b=sub_sum(L)
print(b)
2021-01-10
hello='Hello'
space=' '
world='World'
print(hello+space+world)
space=' '
world='World'
print(hello+space+world)
2021-01-09
最赞回答 / the_tops
template = '{0}, {1}'result = template.format('WorldLife is short', 'you need Python .')print(result)template = '{w}, {c}'World = 'WorldLife is short'you = 'you need Python .'result1 = template.format(w = World, c = you)print(result1)
2021-01-08
L=[75,92,59,68,99]
sum=0.0
for ch in L:
sum=sum+ch
print(sum/5)
sum=0.0
for ch in L:
sum=sum+ch
print(sum/5)
2021-01-07
age=8
if age>=18:
print('adult')
elif age>=6:
print('teenager')
elif age>=3:
print('kid')
else:
print('baby')
if age>=18:
print('adult')
elif age>=6:
print('teenager')
elif age>=3:
print('kid')
else:
print('baby')
2021-01-07
age=8
if age>=18:
print('adult')
elif age>=6:
print('teenager')
elif age>=3:
print('kid')
else:
print('baby')
if age>=18:
print('adult')
elif age>=6:
print('teenager')
elif age>=3:
print('kid')
else:
print('baby')
2021-01-07
>>> dongdongqiang=19
>>> if dongdongqiang>18:
... print('adult')
...
adult
>>> if dongdongqiang>18:
... print('adult')
...
adult
2021-01-07
>>> s='AABCDEFGHHIJ'
>>> abcdefgh=s[1:9]
>>> print(abcdefgh)
ABCDEFGH
>>> abcdefgh=s[1:9]
>>> print(abcdefgh)
ABCDEFGH
2021-01-07