Python tutorial

Python tutorial

Ejemplos básicos – Funciones

"""
       =====================================================
       =========    PRUEBAS CON FUNCIONES   ================
       =====================================================
"""
import random
import math
# ---------------------------------------------------------------------
def funcionSuma(arg1, arg2):
    valor = arg1 + arg2
    return valor

def funcionProducto(arg1, arg2):
    valor = arg1 * arg2
    return valor

def funcionSumaMultiple(*args):
    valor =0 
    argumentos = len(args)
    coma =""
    valores =""
    for x in args:
        valor = valor + x
        valores = valores + coma + str(x) 
        coma = ", "
    return "Funcion: " + str(argumentos) + " argumentos (" + valores + ") suma total: " + str(valor) 

def funcionMultiplica(redondeo= 1, arg1 = 1 ,arg2 = math.pi):
    valor = arg1 * arg2
    valor = round(valor,redondeo)
    return "Funcion: " + str(arg1) + " * "  + str(arg2) + " redondea (" + str(redondeo) + ") Total= " + str(valor)


# ---------------------------------------------------------------------
print ("--------- --------- --------- --------- --------- ")
print ("--------- --------- --------- --------- --------- ")
print ("--------- --------- --------- --------- --------- ")
print("Suma 45 + 55 = " + str(funcionSuma(45,55)))
valor=funcionSuma(238,38)
print("Suma 238 + 38 = " + str(valor))
valor=funcionProducto(6,7)
print("producto de 6 * 7 = " + str(valor))

print(funcionSumaMultiple(6,7,8))
print(funcionSumaMultiple(10,10,10,50))
print(funcionSumaMultiple(10.88,0.11))
print(funcionSumaMultiple(random.randrange(1,100),random.randrange(1,100)))
print(funcionMultiplica(4,100))

print ("--------- --------- --------- --------- --------- ")