def mainindividual(ind1, ind2, rank): lenth = len(ind1) ranklist = [] count = 1 while count <= lenth: ranklist.append(count) count += 1 Sym = sym(ranklist).copy() #print(Sym) position = 1 summ = [] while position <= lenth: for grpele in Sym: stens1 = sort(tensor1(ind1, ind2, grpele, position, rank)) stens2 = sort(tensor2(ind1, ind2, grpele, position, rank)) if stens1 != []: summ.append(stens1) if stens2 != []: summ.append(stens2) #print(stens1) #print(stens2) position += 1 #print(summ) tures = sum(summ) return tures
def test_sum_001(self): data = [1, 2, 3] result = sum(data) self.assertEqual(result, 6)
def main(): """ 实例:测试多个命令,sum,sub,div 依次添加命令,并为命令添加参数 """ # 创建解析对象 parser = argparse.ArgumentParser(description="") # 需要解析多个命令时,创建子对象 subparser = parser.add_subparsers(dest="command", help="commands") # 添加子命令,并为子命令添加参数 parser_sum = subparser.add_parser("sum") parser_sum.add_argument("x", type=int) parser_sum.add_argument("y", type=int) parser_sub = subparser.add_parser("sub") parser_sub.add_argument("x", type=int) parser_sub.add_argument("y", type=int) parser_div = subparser.add_parser("div") parser_div.add_argument("x", type=int) parser_div.add_argument("y", type=int) args = parser.parse_args() command = args.command if command == "sum": print(sum(args.x, args.y)) elif command == "sub": print(sub(args.x, args.y)) elif command == "div": print(div(args.x, args.y)) else: parser.parse_args(["--help"])
def test_sum(self): a = [random.randint(1, 100) for _ in range(5)] ans = _("The sum of the {} first integers is {} and you returned {}.") for i in range(len(a)): stu_ans = sum.sum(a[i]) corr_ans = corr.sum(a[i]) self.assertEqual(corr_ans, stu_ans, ans.format(a[i], corr_ans, stu_ans))
def main(): if square(50) != 50**2: print("Square function does not work") if cube(50) != 50**3: print("Cube function does not work") numbers = [1, 2, 3, 4, 5] if sum(numbers) != 15: print("Sum function does not work")
def sum(self): try: a = int(self.ui.input_A.text()) b = int(self.ui.input_B.text()) result = str(sum.sum(a, b)) except: result = "두개를 더할수 없습니다" self.ui.Sum_result.setText(result)
def test_float(self): lists = [[random.random() for _ in range(random.randint(1, 20))] for _ in range(random.randint(1, 20))] ans = _( "The sum of {} is {} and you returned {}. Do you handle floats?") for i in range(len(lists)): stu_ans = sum.sum(lists[i]) corr_ans = corr.sum(lists[i]) self.assertEqual(corr_ans, stu_ans, ans.format(lists[i], corr_ans, stu_ans))
def main(args): a = 1 b = 6 c = 9 x = args.x print("Lets compute the polynomial of %d*x^3 + %d*x^2 + %d*x" % (a, b, c)) result = sum([a * cube(x), b * square(x), c * x]) print("The result is %d" % result) true_result = a * x**3 + b * x**2 + c * x if true_result == result: print("Success class complete!") else: print("Woops. Try again")
def lsymtenmult(ind, tens, rank): product = [] lenth = len(ind) lenlist = [] count = 1 while count <= lenth: lenlist.append(count) count += 1 Sym = sym(lenlist).copy() for grpele in Sym: permuind = [] countass = 1 while countass <= lenth: permuind.append(ind[grpele[countass - 1] - 1]) countass += 1 for addtens in tens: addprod = [] tenind = 1 #print(addprod[0]) coeff = addtens[0] #addprod.append(coeff) while tenind <= lenth: coord = [] t = tenind # print(t) #print("a") coord.append(ind[grpele[t - 1] - 1]) coord.append(addtens[t]) # print(coord) ij = nrc(coord[0], rank).copy() kl = nrc(coord[1], rank).copy() #print(coord) # print(kl) if ij[1] == kl[0]: appd = rcn(ij[0], kl[1], rank) addprod.append(appd) # print(tens1) else: addprod = [] break tenind += 1 if addprod != []: sortedprod = sort(addprod) sortedprod.insert(0, coeff) product.append(addprod) #print(product) if product != []: prod = sum(product) #sum帮助我们合并同类项 else: prod = [] return prod
def test_char(self): lists = [[ random.randint(1, 100) for _ in range(random.randint(1, 20)) ] for _ in range(random.randint(1, 20))] ans = _( "The sum list provided was {}. Did you take care of everything? ") for i in range(len(lists)): lists[i].append('e') try: stu_ans = sum.sum(lists[i]) corr_ans = corr.sum(lists[i]) self.assertEqual(corr_ans, stu_ans, ans.format(lists[i])) except TypeError: self.assertFalse(True, ans.format(lists[i]))
def test_char(self): lists = [[ random.randint(1, 100) for _ in range(random.randint(1, 20)) ] for _ in range(random.randint(1, 20))] ans = _( "The sum list provided was {}. The type() method may be able to help you. " ) for i in range(len(lists)): lists[i].append('e') try: stu_ans = sum.sum(lists[i]) corr_ans = corr.sum(lists[i]) self.assertEqual(corr_ans, stu_ans, ans.format(lists[i])) except TypeError: self.assertFalse(True, ans.format(lists[i]))
import sum as s print("ciao " + str(s.sum(7, 3)))
def test_sum(self): self.assertEqual(sum.sum(4, 5), 9)
import time from numpy import arange # Use larger array for numpy/pyrex than for python # because the pytohn version is so slow... a = arange(1.e6) print 'elements:', len(a) t1 = time.time() res = sum(a) t2 = time.time() print 'python sum(approx sec, result):', (t2 - t1) * 10, res a = arange(1.e7) t1 = time.time() res = a.sum() t2 = time.time() print 'numpy sum(sec, result):', t2 - t1, res from sum import sum t1 = time.time() res = sum(a) t2 = time.time() print 'pyrex sum(sec, result):', t2 - t1, res
def test_one(): assert sum(1) == 1
def test_additions_are_additive(self): assert sum(1, 1) == 2, "expected two numbers to add up"
def test_should_add(self): "it adds two integers and returns integer" self.assertEqual(sum(1, 2), 3) self.assertEqual(sum(3, 2), 5)
for x in letters: print(x) for x in range(0,5,2): print (x); def name (item): print (item); name('who are you '); import sum; sum.sum(10,12); from sum import length ; length([',','2']); file = open('/Users/liuwei/Desktop/Python/demo1/hello.txt','r+'); str = file.read(8); file.write('i love you') print(file.name) print(str);
def test_sum01(self): self.assertEqual(1, sum(0, 1))
def test_sum_fail(self): self.assertFalse(sum.sum(4, 5) == 8)
def test_sum(): for i in range(1000): first = randint(-1000, 1000) / 10 second = randint(-1000, 1000) / 10 assert (sum(first, second) == (first + second))
def test_sum(): assert sum(3, 4) == 7 assert sum(5.5, 12) == 17.5 assert sum(-3, 35) == 32 assert sum(1234, 5678) == 6912
def test_adding_3_2(self): self.assertEqual(sum(3, 2), 5)
def test_three(): assert sum(3) == 6
def test_two(): assert sum(2) == 3
def test_fail(self): self.assertTrue(sum.sum(8, 9), 17)
#!/usr/bin/python3 import concat import sum print(concat.concat("toni ", "costa")) print(sum.sum(7, 20))
import sum print("enter number 1") n1 = int(raw_input()) print("enter number 2") n2 = int(raw_input()) print("sum is") print(sum.sum(n1, n2))
def test_sum(): total = sum.sum(4, 5) assert total == 9
import time from rta import rta from sum import sum from button import button from scene import scene sum = sum() button = button() rta = rta() scene = scene() score = 0 while True: if scene.pressStart(rta, button) == True: break for x in range(0, 3): # Clear the board rta.codeBig("JYM01") time.sleep(1) clickIn = 0 answer = "" answerbit = "" current = x som = sum.createSum()
import time from numpy import arange # Use larger array for numpy/cython than for python # because the pytohn version is so slow... a= arange(1.e6) print 'elements:', len(a) t1 = time.time() res = sum(a) t2 = time.time() print 'python sum(approx sec, result):', (t2-t1)*10, res a= arange(1.e7) t1 = time.time() res = a.sum() t2 = time.time() print 'numpy sum(sec, result):', t2-t1, res from sum import sum t1 = time.time() res = sum(a) t2 = time.time() print 'cython sum(sec, result):', t2-t1, res
def test_is_not_string(self): self.assertRaises(TypeError, sum(5, 'we'))
def test_sum(): assert sum.sum(3, 4) == 7
def test_empty(self): lst = [] ans = _("When the list is empty you should return 0.") self.assertEqual(0, sum.sum(lst), ans)
def test_sum(self): self.assertEqual(sum(5, 4), 9)
""" num1, num2 = input(": ").split() print(num1) print(num2) print("------") """ import sum import mul import dec import div number1 = input("num1 : ") number2 = input("num2 : ") sum.sum(int(number1), int(number2)) dec.dec(int(number1), int(number2)) mul.mul(int(number1), int(number2)) div.div(int(number1), int(number2))
def test_sum10(self): self.assertTrue(1 == sum(1, 0))