def bruteForceMultioly(A, B) : C = [] n = len(A) for i in range(0, n) : row = [] for j in range(0, n) : result = 0 for k in range(0, n) : result += A[i][k] * B[k][j] row.append(result) C.append(row) return C
def bruteForceMultioly(A, B) : C = [] n = len(A) for i in range(0, n) : row = [] for j in range(0, n) : result = 0 for k in range(0, n) : result += A[i][k] * B[k][j] row.append(result) C.append(row) return C
from pprint import pprint n = eval(input("Enter a number: ")) NumbersLessThanInput=[i for i in range(2, n)] PrimeNumbers = [] for i in range(0, len(NumbersLessThanInput)) : IsPrimeFlag = 1 for j in range(0, len(PrimeNumbers)) : if NumbersLessThanInput[i] % PrimeNumbers[j] == 0 : IsPrimeFlag = 0 if IsPrimeFlag == 1: PrimeNumbers += [NumbersLessThanInput[i]] pprint(PrimeNumbers)
هدف محاسبه این عبارت است( که n ورودی سوال است ) :
sum = 1! + 2! + 3! + ... + n!
import math def factoriel(number) : sum = 1 for i in range(1, number+1) : sum *= i return sum n = eval(input("Enter a number : ")) sum = 0; for i in range(1, n+1): sum += factoriel(i) print(sum)
sum = 1! - 2! + 3! + ... (+-) n!
import math def factoriel(number) : sum = 1 for i in range(1, number+1) : sum *= i return sum n = eval(input("Enter a number : ")) sum = 0; for i in range(1, n+1): if i % 2 == 0: sum -= factoriel(i) else : sum += factoriel(i) print(sum)
import math from pprint import pprint def sort(array) : length = len(array); for i in range(0, length) : for j in range(i+1, length) : if array[i] > array[j] : temp = array[i] array[i] = array[j] array[j] = temp return array file_path = "test.txt" file = open(file_path, 'r') count = eval(file.readline()) array = [] for i in range(1, count+1) : number = eval(file.readline()) sqrt = round(math.sqrt(number)) + 1 flag = 0; for i in range(2, sqrt) : if number % i == 0 : flag = 1 if flag == 0 : array = array + [number] pprint(sort(array))
import math file_path = "test.txt" file = open(file_path, 'r') count = eval(file.readline()) counter = 0 for i in range(1, count+1) : number = eval(file.readline()) sqrt = round(math.sqrt(number)) + 1 flag = 0; for i in range(2, sqrt) : if number % i == 0 : flag = 1 if flag == 0 : counter += 1 print ("count of prime numbers is : " + str(counter))