Created
February 2, 2016 18:28
-
-
Save jbsilva/43534420b85740e49897 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*-*- encoding: utf-8 -*-*- | |
# Created: Sun, 31 Jan 2016 09:09:19 -0200 | |
""" | |
Imprime LINHAS conjuntos de seis números cuja soma é igual a SOMA | |
É possível imprimir linhas repetidas. | |
Exemplo: ./soma_constante.py 12000 20 | |
""" | |
import argparse | |
import sys | |
import random | |
__author__ = "Julio Batista Silva" | |
__copyright__ = "Copyright (c) 2016, Julio Batista Silva" | |
__license__ = "GPL v3" | |
__version__ = "1.0" | |
__email__ = "[email protected]" | |
def main(args): | |
soma = args.SOMA | |
for i in range(args.LINHAS): | |
v1 = random.randint(0, soma) | |
v2 = random.randint(0, soma - v1) | |
v3 = random.randint(0, soma - v1 - v2) | |
v4 = random.randint(0, soma - v1 - v2 - v3) | |
v5 = random.randint(0, soma - v1 - v2 - v3 - v4) | |
s = v1 + v2 + v3 + v4 + v5 | |
v6 = soma - s | |
print("{}+{}+{}+{}+{}+{}".format(v1, v2, v3, v4, v5, v6)) | |
return 0 | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser( | |
description='Imprime LINHAS conjuntos de seis números cuja soma é igual a SOMA.') | |
parser.add_argument('SOMA', type=int, help="Valor da soma") | |
parser.add_argument('LINHAS', type=int, help="Quantidade de linhas a serem impressas") | |
parser.add_argument('--version', action='version', | |
version='%(prog)s v' + __version__) | |
args = parser.parse_args() | |
sys.exit(main(args)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment