>
Python 课堂
2020-11-09 15:59
Python
  • 2132
  • 527
  • 64
  • 51


Python 课堂

def sums(num):
    sum3=0
    for i in num:
        sum3+=i;
    return sum3
class Resturant():
    def __init__(self,num):    
        self.num = num
    def sums(self):
        sum3=0
        for i in self.num:
            sum3+=i;
        return sum3
    def jian(self):
        n=0
        for i in self.num:
            n+=1
            if(n==1):
                sum3=i
            else:
                n+=1
                sum3-=i
        return sum3
    def ch(self):
        sum3=1
        for i in self.num:
            sum3*=i
        return sum3
  
    def cu(self):
        n=0
        for i in self.num:
            n+=1
            if(n==1):
                sum3=i
            else:
                sum3/=i
        return sum3
    def abs(self):
        resultList = []
        for i in self.num:
            if (i >= 0):
                resultList.append(i);
            else:
                resultList.append(-i);
        return resultList
		
x=[2,9,-10]
#print(sums(x))
ins_rest = Resturant(x)
print (ins_rest.sums())
print (ins_rest.jian())
print (ins_rest.ch())
print (ins_rest.cu())
print (ins_rest.abs())


全部留言 ()
返回
顶部