最赞回答 / 慕丝7207896
你的变量K没有递增啊,正确代码如下def l_sum1(k): a = 0 b = 0 while b <= k: a += b b += 1 return aprint(l_sum1(100))
2021-03-25
T = (1, 'CH', [3, 4])
T = list(T)
T[2]=tuple(T[2])
print(tuple(T))
T = list(T)
T[2]=tuple(T[2])
print(tuple(T))
2021-03-23
最新回答 / 慕粉1217398274
取模运算的结果就是除法运算的余数,99/30=3余9所以99%3的结果就是9,==>没什么用就是表示个箭头,后面是这行程序运行的结果,#是注释,#后面的部分只会作为文本显示,不作为程序运行
2021-03-22
最新回答 / 慕运维1448452
额,,,,,短路计算,a and b 如果a是false 那么输出就是a 如果a是true 那么输出无论b是true或者false,都是b。你这里a=“pd”然后print(“hello”,a and “world”)a已经赋值字符串pd应该是true!
2021-03-22
已采纳回答 / qq_加油少年_2
template="Life is short,{} " data="you need Python."result=template.format(data) print(result)不要全部写在一行啊
2021-03-21
最新回答 / 慕斯卡8373086
def sums (n): refult = 0 if n > 0 and n <= 100: while n > 0 : refult = refult + n n -= 1 return refult else: return '参数要在1-100之间'n1 = 99print(sums(n1))def fact(n): if n == 1: return 1 ...
2021-03-20
a='python'
print('hello',a and 'world') #==>hello, python
在and语句下,a值为true,所以运算结果取决于前者
b=''
print('hello',b or 'world') #==>hello, world
在or语句下,b值为false(空,0,None),所以运算结果取后者
print('hello',a and 'world') #==>hello, python
在and语句下,a值为true,所以运算结果取决于前者
b=''
print('hello',b or 'world') #==>hello, world
在or语句下,b值为false(空,0,None),所以运算结果取后者
2021-03-20
搞那么复杂
def sub_sum(l):
j_sum=0
o_sum=0
for n in l:
if n%2 == 0 :
o_sum += n
else:
j_sum += n
return j_sum,o_sum
l=[1,3,5,2,4,6,7,8,9,10]
s=sub_sum(l)
print('奇数和={}'.format(s[0]))
print('偶数和={}'.format(s[1]))
def sub_sum(l):
j_sum=0
o_sum=0
for n in l:
if n%2 == 0 :
o_sum += n
else:
j_sum += n
return j_sum,o_sum
l=[1,3,5,2,4,6,7,8,9,10]
s=sub_sum(l)
print('奇数和={}'.format(s[0]))
print('偶数和={}'.format(s[1]))
2021-03-19
# Enter a code
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for v1 in L:
if v1 in S:
S.remove(v1)
else:
S.add(v1)
print(S)
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for v1 in L:
if v1 in S:
S.remove(v1)
else:
S.add(v1)
print(S)
2021-03-19