def count():
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(f())
return fs
print(count())
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(f())
return fs
print(count())
2024-04-03
两层不就够了
from functools import reduce
def cale_prod(list1):
def ji(x,y):
return x*y
return reduce(ji,list1)
list1 = list(map(int, input().split(',')))
print(cale_prod(list1))
from functools import reduce
def cale_prod(list1):
def ji(x,y):
return x*y
return reduce(ji,list1)
list1 = list(map(int, input().split(',')))
print(cale_prod(list1))
2024-04-03
f = open('6.txt', 'a+')
f.seek(0)
content = f.readlines()
f.seek(2)
f.writelines('\n')
f.writelines(content)
f.close()
这样比较合理
f.seek(0)
content = f.readlines()
f.seek(2)
f.writelines('\n')
f.writelines(content)
f.close()
这样比较合理
2024-03-29
优化一下整数
def __str__(self):
g = gcd(self.zi, self.mu) #进行约分
if self.mu/g != 1:
return '{}/{}'.format(int(self.zi/g), int(self.mu/g))
else:
return '{}'.format(int(self.zi/g))
def __str__(self):
g = gcd(self.zi, self.mu) #进行约分
if self.mu/g != 1:
return '{}/{}'.format(int(self.zi/g), int(self.mu/g))
else:
return '{}'.format(int(self.zi/g))
2024-03-27
最新回答 / qq_转身_11
在继承了两个方法的情况下,super()只会调用第一个函数的__init__ 方法,而不会调用第二个函数,所以会出现传参多的问题。修改一下代码,例如:# Enter a codeclass Person(object): def __init__(self, nam...
2024-03-09