Hi everyone,
I have recently been introduced to python in my university and now I have an assignment to submit.
My problem is that I don't have much python programming experience.
I was asked to write a program to:
1. Enter coefficients
2. check solvability
3. Do gauss seidel
4. Do gauss jacobi
I have started writing my "simple" program when I encountered an error which I can't debug. Here are my latest codings:
I haven't done the part on gauss seidel and gauss jacobi. But concerning the second choice in my menu, it returns the :
"UnboundLocalEr ror: local variable 'a1' referenced before assignment"
I really don't know what to do and I have only 2 weeks to submit my assignment. Your assistance will be of a great help.
Thank you in advance for the help you have provided to me and please excuse me if my english was not good.
I have recently been introduced to python in my university and now I have an assignment to submit.
My problem is that I don't have much python programming experience.
I was asked to write a program to:
1. Enter coefficients
2. check solvability
3. Do gauss seidel
4. Do gauss jacobi
I have started writing my "simple" program when I encountered an error which I can't debug. Here are my latest codings:
Code:
def menu():
print"(1) Enter coefficients"
print"(2) Check solvability"
print"(3) Gauss-Seidel"
print"(4) Gauss-Jacobi"
choice=input("Your choice is:")
if 1<=choice<=4:
if choice==1:
coeff()
if choice==2:
check()
else:
print
print"ERROR! Either wrong number chosen or letters have been entered."
print"Please choose a number from 1 to 4 only."
print
def coeff():
try:
global a1
global b1
global c1
global a2
global b2
global c2
global a3
global b3
global c3
global d1
global d2
global d3
a1=input("a1=")
b1=input("b1=")
c1=input("c1=")
a2=input("a2=")
b2=input("b2=")
c2=input("c2=")
a3=input("a3=")
b3=input("b3=")
c3=input("c3=")
d1=input("d1=")
d2=input("d2=")
d3=input("d3=")
print
except:
print
print"Error occured! Please check and re-enter your values."
coeff()
print
def check():
if a1<0:
a1=-a1
if b1<0:
b1=-b1
if c1<0:
c1=-c1
if a2<0:
a2=-a2
if b2<0:
b2=-b2
if c2<0:
c2=-c2
if a3<0:
a3=-a3
if b3<0:
b3=-b3
if c3<0:
c3=-c3
if a1>b1+c1:
if b2>a2+c2:
if c3>a3+b3:
print"This system of linear equations can be solved using Gauss-Jacobi and Gauss-Seidel."
else:
print"This system of linear equations cannot be solved using Gauss-Jacobi and Gauss-Seidel."
while True:
menu()
"UnboundLocalEr ror: local variable 'a1' referenced before assignment"
I really don't know what to do and I have only 2 weeks to submit my assignment. Your assistance will be of a great help.
Thank you in advance for the help you have provided to me and please excuse me if my english was not good.
Comment