Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions printNumbers/functions/square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
#
# square.py
#
# This file is part of printNumbers.
#
# Copyright (C) 2022 P. Carlsson, IEK-8, FZ Juelich
#
# printNumbers is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# printNumbers is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with printNumbers. If not, see <http://www.gnu.org/licenses/>.

def square(n):
'''
:param n: Operand
:return: n*n
'''

return (n*n)
6 changes: 5 additions & 1 deletion printNumbers/printNumbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
"""
Usage:
printNumbers.py -h --help
printNumbers.py [--fibonacci|--factorial] <operand>
printNumbers.py [--fibonacci|--factorial|--square] <operand>

Options:
-h --help Print usage.
--fibonacci Print the fibonacci sequence.
--factorial Print the factorial.
--square Print the square of the operand.
"""

from docopt import docopt
Expand All @@ -45,6 +46,7 @@
#
functionTable = { CONST_FUNC_CODE_FIBONACCI : FibonacciSequence,
CONST_FUNC_CODE_FACTORIAL : Factorial,
CONST_FUNC_CODE_SQUARE : Square,
}

#
Expand All @@ -67,3 +69,5 @@
print('fib(' + str(params.operand) + ') =', result)
elif params.functionIndex == CONST_FUNC_CODE_FACTORIAL:
print(str(params.operand) + '! =', str(result))
elif params.functionIndex == CONST_FUNC_CODE_SQUARE:
print(str(params.operand) + ' squared is ', str(result))