寫(xiě)程序看來(lái)數(shù)學(xué)的基礎(chǔ)概念必須明了切扎實(shí)。
2024-01-12
最新回答 / 翎棟
#?-*-?coding:?utf-8?-*-# 加上上面這個(gè)注釋就可以帶有中文的注釋了b = "Python"print("Life is short, you need {c}".format(c=b))print("Life is short, you need {0}".format("Python"))# no chinese world or?
2024-01-11
最贊回答 / 立城大渣渣
因?yàn)橐矝](méi)教你接收update()的返回值啊。不賦值直接調(diào)用就行了,你這里的set_old已經(jīng)是存儲(chǔ)了更新后的結(jié)果
2024-01-02
# Enter a code
def greet(what = 'world'):
print('Hello,{}'.format(what))
def greet(what = 'world'):
print('Hello,{}'.format(what))
2023-12-27
# Enter a code
def func(x):
if isinstance(x, list):
return sum(x)
elif isinstance(x, tuple):
multi = 1
for n in x:
multi *= n
return multi
def func(x):
if isinstance(x, list):
return sum(x)
elif isinstance(x, tuple):
multi = 1
for n in x:
multi *= n
return multi
2023-12-27
# coding=utf-8
def sum_func(n):
if n <= 1:
return 1
else:
return (n + sum_func(n-1))
def sum_for():
total = 0
for n in range(1, 101):
total += n
return total
def sum_func(n):
if n <= 1:
return 1
else:
return (n + sum_func(n-1))
def sum_for():
total = 0
for n in range(1, 101):
total += n
return total
2023-12-27
# Enter a code
L = []
for n in range(1, 101):
L.append(n*n)
print(L)
print(sum(L))
L = []
for n in range(1, 101):
L.append(n*n)
print(L)
print(sum(L))
2023-12-27
# Enter a code
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if not s1.isdisjoint(s2):
print(s1.intersection(s2))
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if not s1.isdisjoint(s2):
print(s1.intersection(s2))
2023-12-27
# Enter a code
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for n in L:
if n not in S:
S.add(n)
else:
S.remove(n)
print(S)
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for n in L:
if n not in S:
S.add(n)
else:
S.remove(n)
print(S)
2023-12-27
# Enter a code
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.append('Zero')
L.append('Phoebe')
L.append('Gen')
L.sort()
print(L)
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.append('Zero')
L.append('Phoebe')
L.append('Gen')
L.sort()
print(L)
2023-12-27
T = ('Alice', 'Bob', 'Candy', 'David', 'Ellena')
# 通過(guò)下標(biāo)的方式訪(fǎng)問(wèn)元素
print(T[0]) # ==> Alice
print(T[4]) # ==> Ellena
# 切片
print(T[1:3]) # ==> ('Bob', 'Candy')
candy錯(cuò)了吧,應(yīng)該是David吧
# 通過(guò)下標(biāo)的方式訪(fǎng)問(wèn)元素
print(T[0]) # ==> Alice
print(T[4]) # ==> Ellena
# 切片
print(T[1:3]) # ==> ('Bob', 'Candy')
candy錯(cuò)了吧,應(yīng)該是David吧
2023-12-25
num = 3.14 * 1.57
print (round (num , 2))
round 需要嵌套在print里面
print (round (num , 2))
round 需要嵌套在print里面
2023-12-19
最贊回答 / 翎棟
L = [75, 92, 59, 68, 99]def avg(l):? ? return sum(l) / len(l)def avg2(l):? ? sum1 = 0? ? for i in? l:? ? ? ? sum1 += i? ? return sum1 / len(l)average = avg2(L)print(average)
2023-12-19
最新回答 / 快樂(lè)雞哥
sum=0是給總成績(jī)一開(kāi)始賦0,根據(jù)循環(huán),依次把L列表中的分?jǐn)?shù)加到sum中??梢岳斫鉃?+75、0+75+92、...
2023-12-19
最新回答 / 還能學(xué)
for循環(huán)L1分別會(huì)是 [1,2,3]|[5,3,2]|[7,3,2]? ? ? ? ? ? L1[0]? ? ? ? ? ?0 1 2? 0 1 2? ?0 1 2? ? ? ? ? ?每次取L1的0號(hào)元素
2023-12-15