#🔒 i get a syntax error which is " unexpected EOF while parsing" what is the error can u plz help?

19 messages · Page 1 of 1 (latest)

red plover
#

def gauss_elimination(A, B):
n = len(B)
# Applying Gauss elimination
for i in range(n):
# Partial pivoting
max_index = i
for j in range(i+1, n):
if abs(A[j][i]) > abs(A[max_index][i]):
max_index = j
A[i], A[max_index] = A[max_index], A[i]
B[i], B[max_index] = B[max_index], B[i]

    # Forward elimination
    for j in range(i+1, n):
        factor = A[j][i] / A[i][i]
        for k in range(i, n):
            A[j][k] -= factor * A[i][k]
        B[j] -= factor * B[i]

# Back substitution
X = [0] * n
for i in range(n - 1, -1, -1):
    X[i] = B[i] / A[i][i]
    for j in range(i):
        B[j] -= A[j][i] * X[i]
return X

Example equations: ax + by + cz + dw = e

Replace the coefficients and constants with your actual values

A = [
[2, 1, -1, 3], # Coefficients of x
[1, 1, 1, 2], # Coefficients of y
[1, -1, 2, 1], # Coefficients of z
[3, -2, 1, 4] # Coefficients of w
]

B = [4, 7, 1, 12] # Constants on the right-hand side of the equations

Solve the system of equations

solution = gauss_elimination(A, B)
print("Solution:", solution

deep steppeBOT
#

@red plover

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

dense wharf
#

have you forgotten that closing bracket?

red plover
#

where

dense wharf
#

there's no closing bracket on the last statement

#
print("Solution:", solution
red plover
#

ah thx a lot

dense wharf
#

np

#

u can close the channel with !close

#

or continue if you have another problem

red plover
#

how can i write my scripts like u wrote

red plover
dense wharf
#

!code

deep steppeBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

red plover
#

thx again

#

def gauss_elimination(A, B):
n = len(B)
# Applying Gauss elimination
for i in range(n):
# Partial pivoting
max_index = i
for j in range(i+1, n):
if abs(A[j][i]) > abs(A[max_index][i]):
max_index = j
A[i], A[max_index] = A[max_index], A[i]
B[i], B[max_index] = B[max_index], B[i]

    # Forward elimination
    for j in range(i+1, n):
        factor = A[j][i] / A[i][i]
        for k in range(i, n):
            A[j][k] -= factor * A[i][k]
        B[j] -= factor * B[i]

# Back substitution
X = [0] * n
for i in range(n - 1, -1, -1):
    X[i] = B[i] / A[i][i]
    for j in range(i):
        B[j] -= A[j][i] * X[i]
return X

Example equations: ax + by + cz + dw = e

Replace the coefficients and constants with your actual values

A = [
[2, 1, -1, 3], # Coefficients of x
[1, 1, 1, 2], # Coefficients of y
[1, -1, 2, 1], # Coefficients of z
[3, -2, 1, 4] # Coefficients of w
]

B = [4, 7, 1, 12] # Constants on the right-hand side of the equations

Solve the system of equations

solution = gauss_elimination(A, B)
print("Solution:", solution

deep steppeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

🔒 i get a syntax error which is " unexpected EOF while parsing" what is the error can u plz help?