diff --git a/ming/python/1_hello_world/hello_world.py b/ming/python/1_hello_world/hello_world.py new file mode 100644 index 0000000..1d96289 --- /dev/null +++ b/ming/python/1_hello_world/hello_world.py @@ -0,0 +1,8 @@ +#!/bin/python3 +# +# https://www.hackerrank.com/challenges/py-hello-world/problem +# print "Hello, World!" to stdout + + +if __name__ == '__main__': + print("") diff --git a/ming/python/2_if_else/if_else.py b/ming/python/2_if_else/if_else.py new file mode 100644 index 0000000..65e55c4 --- /dev/null +++ b/ming/python/2_if_else/if_else.py @@ -0,0 +1,10 @@ +#!/bin/python3 +# +# https://www.hackerrank.com/challenges/py-if-else/problem +# Given a positive integer n where 1 <= n <= 100 +# If n is even and in the inclusive range of 6 to 20, print "Weird" +# If n is even and greater than 20, print "Not Weird" + + +if __name__ == '__main__': + n = int(input().strip()) diff --git a/ming/python/3_arithmetic_operators/arithmetic_operators.py b/ming/python/3_arithmetic_operators/arithmetic_operators.py new file mode 100644 index 0000000..ebec966 --- /dev/null +++ b/ming/python/3_arithmetic_operators/arithmetic_operators.py @@ -0,0 +1,14 @@ +#!/bin/python3 +# +# https://www.hackerrank.com/challenges/python-arithmetic-operators/problem +# +# Read two integers from STDIN and print three lines where: +# +# The first line contains the sum of the two numbers. +# The second line contains the difference of the two numbers (first - second). +# The third line contains the product of the two numbers. + + +if __name__ == '__main__': + a = int(input()) + b = int(input()) diff --git a/ming/python/4_loops/loops.py b/ming/python/4_loops/loops.py new file mode 100644 index 0000000..23bec6d --- /dev/null +++ b/ming/python/4_loops/loops.py @@ -0,0 +1,28 @@ +#!/bin/python3 +# +# https://www.hackerrank.com/challenges/python-loops/problem +# +# For all non-negative integers i < n, print i^2. +# +# Sample Input: +# 5 +# +# Sample Output: +# 0 +# 1 +# 4 +# 9 +# 16 + +def looping(num): + for i in range(num): + print(square(i)) + + +def square(num): + return num**2 + + +if __name__ == '__main__': + n = int(input()) + looping(n) diff --git a/ming/python/4_loops/loops_test.py b/ming/python/4_loops/loops_test.py new file mode 100644 index 0000000..0cd22de --- /dev/null +++ b/ming/python/4_loops/loops_test.py @@ -0,0 +1,31 @@ +#!/bin/python3 + +import unittest + +from loops import square + + +class TestSquare(unittest.TestCase): + + def square_base_test(self, num, expected_outcome): + result = square(num) + self.assertEqual(result, expected_outcome) + + def test_negative_num(self): + self.square_base_test(-1, 1) + + def test_zero(self): + self.square_base_test(0, 0) + + def test_one(self): + self.square_base_test(1, 1) + + def test_five(self): + self.square_base_test(5, 25) + + def test_ten(self): + self.square_base_test(10, 100) + + +if __name__ == '__main__': + unittest.main()