Post Reply 
Problem with python program
11-04-2023, 03:29 PM
Post: #3
RE: Problem with python program
Auto-formatted using black:
Code:
def simpson(h, suma, cant):
    if cant % 2 != 1:
        print("Debe ingresar un numero impar de nodos")
    else:
        for i in range(1, cant + 1):
            print("Ingrese la imagen del nodo numero ", i)
            x = float(input())
            if i == 1 or i == cant:
                suma += x
            elif i % 2 == 1:
                suma += 2 * x
            elif i % 2 == 0:
                suma += 4 * x
        final = (h / 3) * (suma)
        print("El resultado numerico es: ", final)
    return final


def trapezio(h, suma, cant):
    for i in range(1, cant + 1):
        print("Ingrese la imagen del nodo numero ", i)
        x = float(input())
        if i == 1 or i == (cant):
            suma += x
        else:
            suma += 2 * x
    final = (h / 2) * (suma)
    print("El resultado numerico es: ", final)
    return final


suma = 0
m = int(input("Ingresar 1 para simpson y 2 para trapezio"))
h = float(input("Distancia entre nodos (h): "))
cant = int(input("Ingrese la cantidaad de nodos a usar (n+1): "))

if m == 1:
    resultado = simpson(h, suma, cant)
elif m == 2:
    resultado = trapezio(h, suma, cant)

In the simpson function the first indent is 8 instead of 4 blanks.

(11-04-2023 01:11 PM)BruceH Wrote:  And this is exactly why the decision to make Python reliant on indentation was so <bleah>.

Just use an editor that replaces tabs with 4 blanks.

The problem here was that quote and code blocks were mixed.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Problem with python program - Simon_arg - 11-03-2023, 09:30 PM
RE: Problem with python program - BruceH - 11-04-2023, 01:11 PM
RE: Problem with python program - Thomas Klemm - 11-04-2023 03:29 PM
RE: Problem with python program - komame - 11-04-2023, 03:34 PM
RE: Problem with python program - komame - 11-08-2023, 07:32 AM



User(s) browsing this thread: 1 Guest(s)