Python Forum
Mysterious Indentation Problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mysterious Indentation Problem
#1
Hello !

Spyder tells me i've an indentation problem here, line 4, "unexpected indent" :

def A(i, j, Nz, Nr, dr, dz, dt, he, Bir, Biz) :
    if i == 1 :
        if j == 1 :                                                              "partie 1"
            return ((1/(16*dt))+(1/(8*dz**2))+(1/(4*he*he*dr*dr))+(Biz/(8*dz)))
        elif j==Nr :                                                            "partie 3"
            return ((Nr-1)/(2*dt))+(Bir*(Nr-1)/(2*he*he*dr))+(Biz*(Nr-1)/dz)+((Nr-1)/dz**2)+((Nr-1.5)/(2*he*he*dr*dr))
        else :                                                                  "partie 2"
            return (j-1)*((1/(2*dt))+(1/(he*dr)**2)+(1/dz**2)+(Biz/dz))
    elif j==1 :
        if i==Nz :                                                              "partie 7"
            return (1/(16*dt))+(1/(16*dz**2))+(1/(4*dr*dr*he*he))+(Biz/(8*dz))
        else :                                                                  "partie 4"
            return (1/(8*dt))+(2/(8*dz))+(1/(2*he*he*dr*dr))
    elif i==Nz :
        if j==Nr :                                                              "partie 9"
            return ((Nr-1.5)/(he*he*dr*dr))+(Nr-1)*((1/2*dt)+(Bir/(2*he*he*dr))+(Biz/dz)+((1/dz**2)))
        else :                                                                  "partie 8"
            return (j-1)*((1/(2*dt))+(1/(he*he*dr*dr))+(1/(dz**2))+(Biz/dz))
    elif j==Nr :                                                                "partie 6"
        return ((Nr-1.5)/(he*he*dr*dr))+(Nr-1)*((1/(2*dt))+(Bir/(he*he*dr))+(Biz/dz)+(1/dz**2))
    else :                                                                      "partie 5"
        return (j-1)*((1/dt) + (2/(he*dr)**2) + (2/dz**2))
I've tried online website that shows errors in indentation, trying to replace tabs by spaces, avoiding blank lines, etc... Python doesn't want a loop in another loop (i have the same problem with a "while" loop in a "for" loop). It wants me to put the "return" line 4 at the same level as the "if" line 3. If I do it (because I've tried almost everything), the unexpected indentation error goes to the next line, etc. I don't know what to do, I've asked friends and read others forums (and this one too) before but I can't find a solution.

While you're here, it also does me a "syntax error" here, line 5 :

import numpy as np

""" Paramètres : """

tf = 5                                                                         "temps final"
N =  1                                                                         "nombre d'incréments de temps"
t_laser = 1                                                                    "durée de l'émission laser"
dt = tf / N                                                                    "pas de temps"
DT = dt * alpha / H^2                                                          "pas de temps adimensionné"
Thank you for your help !
Reply


Messages In This Thread
Mysterious Indentation Problem - by Dakodak - Jun-20-2019, 03:10 PM
RE: Mysterious Indentation Problem - by ichabod801 - Jun-20-2019, 04:36 PM
RE: Mysterious Indentation Problem - by Dakodak - Jun-21-2019, 06:55 AM
RE: Mysterious Indentation Problem - by noisefloor - Jun-21-2019, 07:02 AM
RE: Mysterious Indentation Problem - by Dakodak - Jun-21-2019, 07:08 AM
RE: Mysterious Indentation Problem - by DeaD_EyE - Jun-21-2019, 07:38 AM
RE: Mysterious Indentation Problem - by Dakodak - Jun-21-2019, 09:52 AM
RE: Mysterious Indentation Problem - by noisefloor - Jun-21-2019, 11:11 AM
RE: Mysterious Indentation Problem - by ichabod801 - Jun-21-2019, 12:38 PM
RE: Mysterious Indentation Problem - by noisefloor - Jun-21-2019, 01:49 PM
RE: Mysterious Indentation Problem - by metulburr - Jun-21-2019, 03:35 PM
RE: Mysterious Indentation Problem - by Dakodak - Jun-24-2019, 06:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysterious Extra New-Line trevorkavanaugh 2 2,503 Feb-27-2019, 07:13 PM
Last Post: trevorkavanaugh
  Indentation if/else problem Rikk 3 2,800 May-25-2018, 01:10 PM
Last Post: buran
  Mysterious syntax errors... help? friendlymegalomaniac 3 3,014 Apr-26-2018, 09:22 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020