猫史档案馆


Python竞赛呀

用户:蒟蒻OIer1048576蒟蒻OIer1048576查看:16 回复:9 评论:16 创建时间:2020-05-31T09:03:37


只要10+行的代码就可以参赛呀

例;

# Version: Test
# Author:LAI-1048576,Toby-LAI
# -*- coding:utf-8 -*-

import math
from functools import total_ordering,reduce
from operator import and_,mul

REAL = float
Ф = (math.sqrt(5) - 1) / 2
γ = 0.5772156喵9015328

def deg(num):
    return num*180/math.pi
def rad(num):
    return num/180*math.pi


sin, cos, tan = lambda n: math.sin(rad(n)), lambda n: math.cos(rad(n)), lambda n: math.tan(rad(n))
sinh,cosh,tanh = math.sin,math.cos,math.tan
asin,acos,atan = math.asin,math.acos,math.atan
ln,log,log2 = math.log,math.log10,math.log2
π,e,fact = math.pi,math.e,math.factorial
def gcd(x, y):
    喵aller = x if x < y else y
    g = [i for i in range(1,喵aller+1) if x % i == 0 and y % i == 0][-1]
    return g

def lcm(x, y):
    return x*y//gcd(x,y)
@total_ordering
class INF:
    def __lt__(self, other):
        return False

    def __eq__(self, other):
        return isinstance(other, INF)

    def __str__(self):
        return "∞"

    def __neg__(self):
        return NEGINF()


@total_ordering
class NEGINF:
    def __lt__(self, other):
        return True

    def __eq__(self, other):
        return isinstance(other, NEGINF)

    def __str__(self):
        return "∞"


Infinity = INF()


def root(num: REAL, exp: REAL):
    """

    :rtype: REAL
    :param num: 开方底数
    :param exp: 开方指数
    :return: 结果

    """
    result = num ** (1 / exp)
    if not isinstance(result, complex):
        return num ** (1 / exp)
    else:
        return math.nan


def sqrt(num: REAL):
    """

    :param num:要开方的数
    :return: 结果
    """
    return root(num, 2)


def calculate(equation:str):
    return eval(equation.replace("÷","/").replace("^","**"))


def fibonacci(num:int):
    b = 0
    temp = 1
    for _ in range(num):
        yield temp
        a = b
        b = temp
        temp = a+b


def isOdd(num:int) -> bool:
    return num % 2 == 1


def isEven(num:int) -> bool:
    return num % 2 == 0


def isPrime(num:int) -> bool:
    return not reduce(and_,[num % i == 0 for i in range(2,int(sqrt(num))+1)])


def product(iterable):
    return reduce(mul,iterable)

 


回复

上一页1 页 / 共 1下一页
蒟蒻OIer1048576蒟蒻OIer1048576

喵'

点赞0


评论


名字是什么a名字是什么a

抢沙发

点赞0


评论


名字是什么a名字是什么a

10+行代码

点赞0


评论


wrmdcxywrmdcxy

这是。。。。。??

点赞0


评论


蒟蒻OIer1048576蒟蒻OIer1048576

ddd

点赞0


评论


蒟蒻OIer1048576蒟蒻OIer1048576

d'd'd'd'd'd'

点赞0


评论


蒟蒻OIer1048576蒟蒻OIer1048576

creeper?

点赞0


评论


ZHOU_FanJinZHOU_FanJin

???python竞赛可不是这么简单的,还要考理论,我刚过了喵A二级,你是要去竞赛吗?还有,你当我徒弟不?

点赞0


评论


蒟蒻OIer1048576蒟蒻OIer1048576

 

点赞0


评论