def f(x):
return pow(x, 0.5)
for item in map(f, range(1, 101)):
if item == int(item):
print(int(item))
def z(item):
if item == int(item):
return print(int(item))
for item in filter(z, [item]):
print(item)
return pow(x, 0.5)
for item in map(f, range(1, 101)):
if item == int(item):
print(int(item))
def z(item):
if item == int(item):
return print(int(item))
for item in filter(z, [item]):
print(item)
from functools import reduce
def f(x, y):
return x * y
print(int(reduce(f, [1.0, 3.0, 5.0, 7.0, 9.0])))
def f(x, y):
return x * y
print(int(reduce(f, [1.0, 3.0, 5.0, 7.0, 9.0])))
import math
def add(a, b, f):
return f(a) + f(b)
print(int(add(1, 4, math.sqrt)))
def add(a, b, f):
return f(a) + f(b)
print(int(add(1, 4, math.sqrt)))
5天前
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
# Enter a code
class Animal(object):
__age = 0
def __init__(self, name, age):
self.__age = age
self.name = name
dog = Animal('Cgo', 20)
print(dog.age)
class Animal(object):
__age = 0
def __init__(self, name, age):
self.__age = age
self.name = name
dog = Animal('Cgo', 20)
print(dog.age)
2023-12-27
# Enter a code
class Animal(object):
count = 0
def __init__(self):
Animal.count += 1
dog = Animal()
cat = Animal()
print(Animal.count)
class Animal(object):
count = 0
def __init__(self):
Animal.count += 1
dog = Animal()
cat = Animal()
print(Animal.count)
2023-12-27
__init__方法使用**kw来接收任意数量的关键词参数。这些参数将被存储在一个字典中,可以通过kw.items()方法遍历。然后,使用setattr方法将这些参数的值设置为实例属性。
2023-12-26