def analysis(): form = request.args data = fn.get_data(form['country'],form['state'],form['type']) sum = fn.sum(data) trend, seasonal, resid = fn.decompose(data) acf = fn.get_acf(data) pacf = fn.get_pacf(data) #q_stat = fn.lb_test(acf) stats = fn.get_stats(data) decomp = {} decomp['trend'] = trend decomp['seasonal'] = seasonal decomp['resid'] = resid data = fn.get_ma(data,7) out = { 'data' : data, 'decomp' : decomp, 'acf' : acf, 'pacf' : pacf, 'stats': stats, 'sum':sum } return render_template('analysis.html', out=out, form=form)
def test_passes_functions(): assert functions.sum(10, 10) == 20 assert functions.product(10, 10) == 100 assert functions.all_branches_pass(1) == 20 assert functions.all_branches_pass(2) == 15 assert functions.all_branches_pass(0) == 10 assert functions.two_branch_fails(True) == 20 assert functions.for_loop_passes(2) == 1 assert functions.for_loop_skipped_passes(0) == 0
def avg(x, y): all_games = [] all_games_score = 0 for i in range(1000000): all_games.append(sum(player(x, y))) for game_score in all_games: all_games_score += game_score avg = all_games_score / len(all_games) return avg
def calc(): operacao = request.args.get('oper', default="soma", type=str) a = request.args.get('a', default=0.0, type=float) b = request.args.get('b', default=0.0, type=float) print(operacao, a, b) resultado = 0.0 if operacao == "soma": resultado = sum(a, b) return jsonify(resultado=resultado)
def calculate(): num1 = float(input("First Number:\n")) operator = str(input("Operator (+, -, *, /):\n")) num2 = float(input("Second Number:\n")) out = None if operator == "+": out = sum(num1, num2) elif operator == "-": out = subtract(num1, num2) elif operator == "*": out = multiply(num1, num2) elif operator == "/": out = divide(num1, num2) print("Resposta: " + str(out))
def player(x, y): all_turns = [] for i in range(10): turn = [] score = 0 while True: turn.append(roll_d6()) if 1 in turn: break if sum(turn) >= x or len(turn) == y: break if 1 in turn: all_turns.append(0) else: for i in turn: score += i all_turns.append(score) return all_turns
def test_doubles(self): self.assertEqual(sum(1.4, 2.2), 3.6)
def test_ints(self): self.assertEqual(sum(2, 2), 4)
def test_invalid(self): with self.assertRaises(TypeError): sum('hello', 2)
getsum = lambda num1, num2: num1 + num2 print(getsum(5, 6)) #in numbers = [1, 2, 4, 5, 8] x = 2 if x in numbers: print('hello') #continue jumps to the next iteration from functions import sum value = sum(9, 8) print(f'the result is {value}') #classes class User: #Constructor def __init__(self, name, email, age): self.name = name self.email = email self.age = age def greeting(self): return f'My name is {self.name}'
"3) Dzielenie \n" "4) Mnożenie \n" "5) Zakończ program \n")) return choice def askUserForNumber(): global numberOne, numberTwo numberOne = int(input("Podaj pierwszą liczbę ")) numberTwo = int(input("Podaj drugą liczbę ")) choice = userChoice() while choice != 5: if choice == 1: askUserForNumber() resultSum = functions.sum(numberOne, numberTwo) print("Wynik dodawania jest równy ", resultSum) elif choice == 2: askUserForNumber() resultSubtract = functions.subtract(numberOne, numberTwo) print("Wynik odejmowania jest równy", resultSubtract) elif choice == 3: askUserForNumber() while numberTwo ==0: print("Pamiętaj nie dziel przez 0!") askUserForNumber() resultDevsion = functions.divide(numberOne, numberTwo) print("Wynik dzielnia jest równy", resultDevsion) elif choice == 4: askUserForNumber() resultMultiply = functions.multiply(numberOne, numberTwo)
print('This program is to practice modules. fucntions.py will be used as a module for practice here.'); #import a default module and test import time; struct_time = time.localtime(time.time()); print();print('Structured Time: ',struct_time); #import user defined module, function.py in this case: import functions print();print("Import functions command executes everything above from function.py. In order to avoid this, we import only specific function from function module."); content = dir(functions); print("Content from functions: ", content); from functions import sum; print();print("We just imported sum from functions, and nothing else was executed."); total = functions.sum(12, 18); print();print("Sum of 12 and 18 using sum function from function module is: ", total);
import functions from functions import diff s = functions.sum(11, 22) print(s) d = diff(22, 11) print(d)
def sum(self, *args, **kwargs): return F.sum(self, *args, **kwargs)
def test_result(self): self.assertEqual(sum(2, 2), 4)
from functions import sum print(sum(2, 3))
def step_impl(context, num1, num2): print(u'PASSO: When I input "{} + {}" to calculator'.format(num1, num2)) context.total = sum(float(num1), float(num2))