Post Reply 
Problem with python program
11-03-2023, 09:30 PM
Post: #1
Problem with python program
Hello everyone,
I recently bought a new G2 and ahve been blown away by how much it can do. However I have been having some problems when trying to load and run some simple python programs I have created. My program is basically a simple algorithm to compute integrals using simpsons rule or trapezium rule. It is written in python 3.11.4 but only uses basic operations, as I input the amount of nodes and the value for the function in said nodes, and it outputs the calculation results. The code works correctly in my computer but it refuses to run in the calculator because of a 'Syntax error'. I am also kind of new to python as a whole, and I have read that programs might need to be modified to run on the g2. If anyone knows how to make this work or if my program wont't run on the g2 I would love to know. I have copied the code below just in case. Thanks in advance.[/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)
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 - 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)