File tree Expand file tree Collapse file tree 8 files changed +125
-10
lines changed Expand file tree Collapse file tree 8 files changed +125
-10
lines changed Original file line number Diff line number Diff line change 1111"""
1212from __future__ import print_function
1313import math
14- from decimal import *
14+ from decimal import Decimal , getcontext
1515
1616try :
1717 raw_input # Python 2
@@ -33,7 +33,31 @@ def solution(n):
3333 0
3434 >>> solution(34)
3535 44
36+ >>> solution(3.4)
37+ 2
38+ >>> solution(0)
39+ Traceback (most recent call last):
40+ ...
41+ ValueError: Parameter n must be greater or equal to one.
42+ >>> solution(-17)
43+ Traceback (most recent call last):
44+ ...
45+ ValueError: Parameter n must be greater or equal to one.
46+ >>> solution([])
47+ Traceback (most recent call last):
48+ ...
49+ TypeError: Parameter n must be int or passive of cast to int.
50+ >>> solution("asd")
51+ Traceback (most recent call last):
52+ ...
53+ TypeError: Parameter n must be int or passive of cast to int.
3654 """
55+ try :
56+ n = int (n )
57+ except (TypeError , ValueError ) as e :
58+ raise TypeError ("Parameter n must be int or passive of cast to int." )
59+ if n <= 0 :
60+ raise ValueError ("Parameter n must be greater or equal to one." )
3761 getcontext ().prec = 100
3862 phi = (Decimal (5 ) ** Decimal (0.5 ) + 1 ) / Decimal (2 )
3963
Original file line number Diff line number Diff line change @@ -28,14 +28,38 @@ def isprime(no):
2828
2929def solution (n ):
3030 """Returns the largest prime factor of a given number n.
31-
31+
3232 >>> solution(13195)
3333 29
3434 >>> solution(10)
3535 5
3636 >>> solution(17)
3737 17
38+ >>> solution(3.4)
39+ 3
40+ >>> solution(0)
41+ Traceback (most recent call last):
42+ ...
43+ ValueError: Parameter n must be greater or equal to one.
44+ >>> solution(-17)
45+ Traceback (most recent call last):
46+ ...
47+ ValueError: Parameter n must be greater or equal to one.
48+ >>> solution([])
49+ Traceback (most recent call last):
50+ ...
51+ TypeError: Parameter n must be int or passive of cast to int.
52+ >>> solution("asd")
53+ Traceback (most recent call last):
54+ ...
55+ TypeError: Parameter n must be int or passive of cast to int.
3856 """
57+ try :
58+ n = int (n )
59+ except (TypeError , ValueError ) as e :
60+ raise TypeError ("Parameter n must be int or passive of cast to int." )
61+ if n <= 0 :
62+ raise ValueError ("Parameter n must be greater or equal to one." )
3963 maxNumber = 0
4064 if isprime (n ):
4165 return n
@@ -54,7 +78,6 @@ def solution(n):
5478 elif isprime (i ):
5579 maxNumber = i
5680 return maxNumber
57- return int (sum )
5881
5982
6083if __name__ == "__main__" :
Original file line number Diff line number Diff line change 66e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17.
77"""
88from __future__ import print_function , division
9- import math
109
1110try :
1211 raw_input # Python 2
1615
1716def solution (n ):
1817 """Returns the largest prime factor of a given number n.
19-
18+
2019 >>> solution(13195)
2120 29
2221 >>> solution(10)
2322 5
2423 >>> solution(17)
2524 17
25+ >>> solution(3.4)
26+ 3
27+ >>> solution(0)
28+ Traceback (most recent call last):
29+ ...
30+ ValueError: Parameter n must be greater or equal to one.
31+ >>> solution(-17)
32+ Traceback (most recent call last):
33+ ...
34+ ValueError: Parameter n must be greater or equal to one.
35+ >>> solution([])
36+ Traceback (most recent call last):
37+ ...
38+ TypeError: Parameter n must be int or passive of cast to int.
39+ >>> solution("asd")
40+ Traceback (most recent call last):
41+ ...
42+ TypeError: Parameter n must be int or passive of cast to int.
2643 """
44+ try :
45+ n = int (n )
46+ except (TypeError , ValueError ) as e :
47+ raise TypeError ("Parameter n must be int or passive of cast to int." )
48+ if n <= 0 :
49+ raise ValueError ("Parameter n must be greater or equal to one." )
2750 prime = 1
2851 i = 2
2952 while i * i <= n :
Original file line number Diff line number Diff line change 1717def solution (n ):
1818 """Returns the smallest positive number that is evenly divisible(divisible
1919 with no remainder) by all of the numbers from 1 to n.
20-
20+
2121 >>> solution(10)
2222 2520
2323 >>> solution(15)
@@ -26,7 +26,31 @@ def solution(n):
2626 232792560
2727 >>> solution(22)
2828 232792560
29+ >>> solution(3.4)
30+ 6
31+ >>> solution(0)
32+ Traceback (most recent call last):
33+ ...
34+ ValueError: Parameter n must be greater or equal to one.
35+ >>> solution(-17)
36+ Traceback (most recent call last):
37+ ...
38+ ValueError: Parameter n must be greater or equal to one.
39+ >>> solution([])
40+ Traceback (most recent call last):
41+ ...
42+ TypeError: Parameter n must be int or passive of cast to int.
43+ >>> solution("asd")
44+ Traceback (most recent call last):
45+ ...
46+ TypeError: Parameter n must be int or passive of cast to int.
2947 """
48+ try :
49+ n = int (n )
50+ except (TypeError , ValueError ) as e :
51+ raise TypeError ("Parameter n must be int or passive of cast to int." )
52+ if n <= 0 :
53+ raise ValueError ("Parameter n must be greater or equal to one." )
3054 i = 0
3155 while 1 :
3256 i += n * (n - 1 )
@@ -39,7 +63,6 @@ def solution(n):
3963 if i == 0 :
4064 i = 1
4165 return i
42- break
4366
4467
4568if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -36,7 +36,31 @@ def solution(n):
3636 229
3737 >>> solution(100)
3838 541
39+ >>> solution(3.4)
40+ 5
41+ >>> solution(0)
42+ Traceback (most recent call last):
43+ ...
44+ ValueError: Parameter n must be greater or equal to one.
45+ >>> solution(-17)
46+ Traceback (most recent call last):
47+ ...
48+ ValueError: Parameter n must be greater or equal to one.
49+ >>> solution([])
50+ Traceback (most recent call last):
51+ ...
52+ TypeError: Parameter n must be int or passive of cast to int.
53+ >>> solution("asd")
54+ Traceback (most recent call last):
55+ ...
56+ TypeError: Parameter n must be int or passive of cast to int.
3957 """
58+ try :
59+ n = int (n )
60+ except (TypeError , ValueError ) as e :
61+ raise TypeError ("Parameter n must be int or passive of cast to int." )
62+ if n <= 0 :
63+ raise ValueError ("Parameter n must be greater or equal to one." )
4064 primes = []
4165 num = 2
4266 while len (primes ) < n :
Original file line number Diff line number Diff line change @@ -28,7 +28,6 @@ def solution():
2828 if (a ** 2 ) + (b ** 2 ) == (c ** 2 ):
2929 if (a + b + c ) == 1000 :
3030 return a * b * c
31- break
3231
3332
3433if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -61,4 +61,4 @@ def solution():
6161
6262
6363if __name__ == "__main__" :
64- print (solution (171 ))
64+ print (solution ())
Original file line number Diff line number Diff line change @@ -40,7 +40,6 @@ def solution(n):
4040 semidivisible = []
4141 for x in range (n ):
4242 l = [i for i in input ().split ()]
43- c1 = 0
4443 c2 = 1
4544 while (1 ):
4645 if len (fib (l [0 ],l [1 ],c2 ))< int (l [2 ]):
You can’t perform that action at this time.
0 commit comments