最新回答 / 翎栋
# -*- coding: utf-8 -*-# 加上上面这个注释就可以带有中文的注释了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
# 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
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')
# 通过下标的方式访问元素
print(T[0]) # ==> Alice
print(T[4]) # ==> Ellena
# 切片
print(T[1:3]) # ==> ('Bob', 'Candy')
candy错了吧,应该是David吧
# 通过下标的方式访问元素
print(T[0]) # ==> Alice
print(T[4]) # ==> Ellena
# 切片
print(T[1:3]) # ==> ('Bob', 'Candy')
candy错了吧,应该是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