Update tasks to use common modules
This commit is contained in:
parent
67a3e75cee
commit
32dd28a565
@ -1,4 +1,8 @@
|
||||
from common import inputTypeCheck
|
||||
try:
|
||||
from common.inputChecking.typeCheck import inputTypeCheck
|
||||
except ModuleNotFoundError:
|
||||
print('Sjekk README.md for hvilke flagg python trenger')
|
||||
exit(1)
|
||||
|
||||
def numberPyramid(length):
|
||||
for i in range(length):
|
||||
@ -26,5 +30,5 @@ def solutionWithGenerator(n):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
n = int(input('n: '))
|
||||
n = inputTypeCheck('n: ', int)
|
||||
print(solutionWithForLoops(n))
|
||||
|
@ -1,3 +1,9 @@
|
||||
try:
|
||||
from common.inputChecking.typeCheck import inputTypeCheck
|
||||
except ModuleNotFoundError:
|
||||
print('Sjekk README.md for hvilke flagg python trenger')
|
||||
exit(1)
|
||||
|
||||
def numberPyramid(length):
|
||||
for i in range(length):
|
||||
print('X', ' ' * i + 'X')
|
||||
@ -10,5 +16,5 @@ def numberPyramidDoubleLoop(length):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
n = int(input('n: '))
|
||||
n = inputTypeCheck('n: ', int)
|
||||
numberPyramidDoubleLoop(n)
|
@ -1,5 +1,10 @@
|
||||
from math import sqrt
|
||||
|
||||
try:
|
||||
from common.inputChecking.typeCheck import inputTypeCheck
|
||||
except ModuleNotFoundError:
|
||||
print('Sjekk README.md for hvilke flagg python trenger')
|
||||
exit(1)
|
||||
|
||||
# O(√n)
|
||||
def isPrime(n):
|
||||
@ -37,7 +42,7 @@ def factorize(n):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
n = int(input('Skriv inn et positivt heltall: '))
|
||||
n = inputTypeCheck('Skriv inn et positivt heltall: ', int)
|
||||
factors = factorize(n)
|
||||
if len(factors) == 1:
|
||||
print(f'{n} er et primtall')
|
||||
|
@ -1,3 +1,9 @@
|
||||
try:
|
||||
from common.inputChecking.typeCheck import inputTypeCheck
|
||||
except ModuleNotFoundError:
|
||||
print('Sjekk README.md for hvilke flagg python trenger')
|
||||
exit(1)
|
||||
|
||||
def alternateSum(n):
|
||||
positiveNumbers = [
|
||||
num**2 for num in [i for i in range(1, n + 1) if i % 2 != 0]
|
||||
@ -9,5 +15,5 @@ def alternateSum(n):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
n = int(input('n: '))
|
||||
n = inputTypeCheck('n: ', int)
|
||||
print(alternateSum(n))
|
@ -1,3 +1,9 @@
|
||||
try:
|
||||
from common.inputChecking.typeCheck import inputTypeCheck
|
||||
except ModuleNotFoundError:
|
||||
print('Sjekk README.md for hvilke flagg python trenger')
|
||||
exit(1)
|
||||
|
||||
def AlternateNumberGenerator():
|
||||
isEven = lambda n: n % 2 == 0
|
||||
n = 1
|
||||
@ -24,5 +30,5 @@ def alternateSumStopAt(k):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
k = int(input('k: '))
|
||||
k = inputTypeCheck('k: ', int)
|
||||
alternateSumStopAt(k)
|
@ -1,3 +1,9 @@
|
||||
try:
|
||||
from common.inputChecking.typeCheck import inputTypeCheck
|
||||
except ModuleNotFoundError:
|
||||
print('Sjekk README.md for hvilke flagg python trenger')
|
||||
exit(1)
|
||||
|
||||
def fibonacciIterative(n):
|
||||
k1 = 0
|
||||
k2 = 1
|
||||
@ -12,7 +18,7 @@ fibonacciSum = lambda n: sum([fibonacciIterative(i) for i in range(1, n + 1)])
|
||||
fibonacciList = lambda n: [fibonacciIterative(i) for i in range(1, n + 1)]
|
||||
|
||||
if __name__ == "__main__":
|
||||
n = int(input('n: '))
|
||||
n = inputTypeCheck('n: ', int)
|
||||
|
||||
print(f'a) Fibonacci({n})', fibonacciIterative(n))
|
||||
print(f'b) Sum av Fibonacci(1..{n})', fibonacciSum(n))
|
||||
|
Loading…
Reference in New Issue
Block a user