## else indent errorr help

A forum for general discussion of the Python programming language.

### else indent errorr help

indent error around towards bottom after else for the random numbers
Code: Select all
`import randomquestion = input("do you want random or input (1 = input 2 = random)")if question == 1:    first = input("first")    second = input("second")    third = input("third")    if first >= second >= third:      print third , second , first      print "range" , first - third      print "average" , (third + second + first)/3      print "medain" , second      if third == first:        print "mode" , first      else:        if second == first:            print "mode" , first        else:            if second == third:                print "mode" , second            else:                print "no mode"    else:        if first <= second <= third:            print first , second , third            print "range" , third - first            print "average" , (third + second + first)/3            print "median" , second            if third == first:              print "mode" , first            else:              if second == first:                print "mode" , first              else:                if second == third:                  print "mode" , second                else:                  print "no mode"        else:            if second >= first >= third:                print third , first , second                print "range" , second-third                print "average" , (third + second + first)/3                print "median" , first                if third == first:                    print "mode" , first                else:                    if second == first:                        print "mode" , first                    else:                        if second == third:                           print "mode" , second                        else:                           print "no mode"            else:               if second >= third >= first:                 print first , third , second                 print "range" , second - first                 print "average" , (third + second + first)/3                 print "median" , third                 if third == first:                   print "mode" , first                 else:                   if second == first:                    print "mode" , first                   else:                    if second == third:                       print "mode" , second                    else:                       print "no mode"               else:                                                                  if third >= first >= second:                        print second , first , third                        print "range" ,third - second                        print "average" , (third + second + first)/3                        print "median" , first                        if third == first:                            print "mode" , first                        else:                            if second == first:                                print "mode" , first                            else:                                if second == third:                                    print "mode" , second                                else:                                    print "no mode"                    else:                        print "error"else:    import random    first = random.randint(1,900000000000000000)    second = random.randint(1,900000000000000000)    third = random.randint(1,900000000000000000)    if first >= second >= third:      print third , second , first      print "range" , first - third      print "average" , (third + second + first)/3      print "medain" , second      if third == first:        print "mode" , first      else:        if second == first:            print "mode" , first        else:            if second == third:                print "mode" , second            else:                print "no mode"    else:        if first <= second <= third:            print first , second , third            print "range" , third - first            print "average" , (third + second + first)/3            print "median" , second            if third == first:              print "mode" , first            else:              if second == first:                print "mode" , first              else:                if second == third:                  print "mode" , second                else:                  print "no mode"          else:            if second >= first >= third:             print third , first , second             print "range" , second-third             print "average" , (third + second + first)/3             print "median" , first             if third == first:                print "mode" , first             else:                if second == first:                    print "mode" , first                else:                    if second == third:                       print "mode" , second                    else:                       print "no mode"             else:                if second >= third >= first:                    print first , third , second                    print "range" , second - first                    print "average" , (third + second + first)/3                    print "median" , third                    if third == first:                      print "mode" , first                    else:                       if second == first:                        print "mode" , first                       else:                        if second == third:                           print "mode" , second                        else:                           print "no mode"                 else:                                                                  if third >= first >= second:                        print second , first , third                        print "range" ,third - second                        print "average" , (third + second + first)/3                        print "median" , first                        if third == first:                         print "mode" , first                        else:                         if second == first:                          print "mode" , first                         else:                          if second == third:                            print "mode" , second                          else:                            print "no mode"                        else:                            print "error"`
Last edited by stranac on Wed Jan 01, 2014 5:51 pm, edited 2 times in total.
funky9819

Posts: 2
Joined: Wed Jan 01, 2014 5:31 pm

### Re: else indent errorr help

viewtopic.php?f=10&t=145

After that, post the traceback.
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: else indent errorr help

I found your error, in fact there are two indentation errors, and now there are two more errors, you cant use two else statements on one if statement. I went and did the indents for you, and i did a list of the indents.

Do Not Use spaces for indentations, use tab:

1. Easier to edit
2.Is more friendly to the eye
3.More organized

Code: Select all
`import randomquestion = input("do you want random or input (1 = input 2 = random)")if question == 1:   first = input("first")   second = input("second")   third = input("third")   if first >= second >= third:      print third , second , first      print "range" , first - third      print "average" , (third + second + first)/3      print "medain" , second      if third == first:         print "mode" , first      else:         if second == first:            print "mode" , first         else:            if second == third:               print "mode" , second            else:               print "no mode"   else:      if first <= second <= third:         print first , second , third         print "range" , third - first         print "average" , (third + second + first)/3         print "median" , second         if third == first:            print "mode" , first         else:            if second == first:               print "mode" , first            else:               if second == third:                  print "mode" , second               else:                  print "no mode"      else:         if second >= first >= third:            print third , first , second            print "range" , second-third            print "average" , (third + second + first)/3            print "median" , first            if third == first:               print "mode" , first            else:               if second == first:                  print "mode" , first               else:                  if second == third:                     print "mode" , second                  else:                     print "no mode"         else:            if second >= third >= first:               print first , third , second               print "range" , second - first               print "average" , (third + second + first)/3               print "median" , third               if third == first:                  print "mode" , first               else:                  if second == first:                     print "mode" , first                  else:                     if second == third:                        print "mode" , second                     else:                        print "no mode"            else:                                                             if third >= first >= second:                  print second , first , third                  print "range" ,third - second                  print "average" , (third + second + first)/3                  print "median" , first                  if third == first:                     print "mode" , first                  else:                     if second == first:                        print "mode" , first                     else:                        if second == third:                           print "mode" , second                        else:                           print "no mode"               else:                  print "error"else:   import random   first = random.randint(1,900000000000000000)   second = random.randint(1,900000000000000000)   third = random.randint(1,900000000000000000)   if first >= second >= third:      print third , second , first      print "range" , first - third      print "average" , (third + second + first)/3      print "medain" , second      if third == first:         print "mode" , first      else:         if second == first:            print "mode" , first         else:            if second == third:               print "mode" , second            else:               print "no mode"   else:      if first <= second <= third:         print first , second , third         print "range" , third - first         print "average" , (third + second + first)/3         print "median" , second         if third == first:            print "mode" , first         else:            if second == first:               print "mode" , first            else:               if second == third:                  print "mode" , second               else:                  print "no mode"      else:         if second >= first >= third:            print third , first , second            print "range" , second-third            print "average" , (third + second + first)/3            print "median" , first            if third == first:               print "mode" , first            else:               if second == first:                  print "mode" , first               else:                  if second == third:                     print "mode" , second                  else:                     print "no mode"            else:               if second >= third >= first:                  print first , third , second                  print "range" , second - first                  print "average" , (third + second + first)/3                  print "median" , third                  if third == first:                     print "mode" , first                  else:                     if second == first:                        print "mode" , first                     else:                        if second == third:                           print "mode" , second                        else:                           print "no mode"               else:                                                                if third >= first >= second:                     print second , first , third                     print "range" ,third - second                     print "average" , (third + second + first)/3                     print "median" , first                     if third == first:                        print "mode" , first                     else:                        if second == first:                           print "mode" , first                        else:                           if second == third:                              print "mode" , second                           else:                              print "no mode"                     else:                        print "error"`

And the indentation list:

Code: Select all
`0001111222223234345451233333434545656234444454565676734555556567678784                                    566666767878989560111112222232343454512333334345456562344444545656767456666676787898956777778789891091078`

I would try using try and except statements
MLP:FIM <3

RainbowShibe

Posts: 10
Joined: Wed Jan 01, 2014 12:39 am
Location: Somewhere Over The Rainbow

### Re: else indent errorr help

RainbowShibe wrote:Do Not Use spaces for indentations, use tab:

It is a widely accepted python convention to use 4 spaces per indent level.

RainbowShibe wrote:1. Easier to edit

Using spaces is no more work than using tabs.
If you think it is, you're doing it wrong.

RainbowShibe wrote:2.Is more friendly to the eye

Huh? Whitespace is invisible, how can using one type be friendlier to the eye?
You can of course choose to display them, but it's still not a big difference(in most editors spaces look nicer, at least imo)

RainbowShibe wrote:3.More organized

How?

Here are a few of my thoughts on why you should use spaces:
• 4 spaces always looks like 4 spaces, a tab's display depends on where you're displaying it
• tabs are equivalent to 8 spaces in python, but most editors display them as 4 by default(this can vary)
• it's a recommendation of the official Style Guide for Python Code
• i'm pretty sure i had at least one more reason when I started typing this, but it seems to have slipped my mind
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: else indent errorr help

stranac wrote:
RainbowShibe wrote:Do Not Use spaces for indentations, use tab:

It is a widely accepted python convention to use 4 spaces per indent level.

RainbowShibe wrote:1. Easier to edit

Using spaces is no more work than using tabs.
If you think it is, you're doing it wrong.

RainbowShibe wrote:2.Is more friendly to the eye

Huh? Whitespace is invisible, how can using one type be friendlier to the eye?
You can of course choose to display them, but it's still not a big difference(in most editors spaces look nicer, at least imo)

RainbowShibe wrote:3.More organized

How?

Here are a few of my thoughts on why you should use spaces:
• 4 spaces always looks like 4 spaces, a tab's display depends on where you're displaying it
• tabs are equivalent to 8 spaces in python, but most editors display them as 4 by default(this can vary)
• it's a recommendation of the official Style Guide for Python Code
• i'm pretty sure i had at least one more reason when I started typing this, but it seems to have slipped my mind

Well, in several different text editing programs there are ways to display the indentations, aswell as spaces, but some do not display the space as a different character, like KWrite or EMacs, while the windows application word or som other can display both, I believe that notepad++ may display one or the other, but working on linux i may have been wrong to assume his OS wasnt windows.
As for organized I'm not sure if it's just me who thinks it is or what, it may also be because on linux a tab doesnt equals 4 or 8 spaces but more like 12 and is very hard to see the difference in spaces.

And as for the reccomended guide, I never really knew, I guess i never took on to look at it, I guess i got use to tabs from Java. Well it was nice to see my post wasnt completely useless since i put in the list of indentations xD
MLP:FIM <3

RainbowShibe

Posts: 10
Joined: Wed Jan 01, 2014 12:39 am
Location: Somewhere Over The Rainbow

### Re: else indent errorr help

RainbowShibe wrote:As for organized I'm not sure if it's just me who thinks it is or what, it may also be because on linux a tab doesnt equals 4 or 8 spaces but more like 12 and is very hard to see the difference in spaces.

Tabs and spaces are each characters. They're bytes. In Python source code, tabs and spaces are used for the same thing, creating code blocks. But nowhere with any amount of sophistication is there any inherent conversion between one and the other. It is a display option in a very local context. Most modern text editors allow you to say, in terms of display, how wide a tab character should be displayed relative to a space character. I will reiterate because this important: it's all about appearance.

Now that we're talking about display and appearance, what's the issue? The issue is consistency. If you mix tabs and spaces, you end up with garbage looking code sometimes. The solution is to change the editor's settings, right? Well, that's a short-term solution. You'll inevitably have to do it again when you view a file that wants the tab to be a different width. You're setting yourself up for failure The Java standard class files that you have source code to have this inconsistency and it's painful to read. Here is an example in ArrayList.class
Code: Select all
`    public int indexOf(Object o) {   if (o == null) {       for (int i = 0; i < size; i++)      if (elementData[i]==null)          return i;   } else {       for (int i = 0; i < size; i++)      if (o.equals(elementData[i]))          return i;   }   return -1;    }`

This is disgusting and damned difficult to read, not to mention that in rare cases you'll even get code which looks valid (the above looks clearly invalid, so you know to change your editor settings) that you'll read wrong! That can cause literally hours of lost productivity, not to mention trichotillomania.

In Python we have a convention of using just spaces. There are arguments for just tabs, but since the community at large is already using spaces, you have the problem that if you use tabs then anyone who adds to your code will cause the previously mentioned problems and when you add to most code in the wild people will yell at you during code reviews, or worse, they won't notice and that stuff will sneak into a code base and bite someone later.

I'll leave you with a quote as a rule of thumb for how to write your code, with the knowledge that someone might lose hours of their life to your decisions
Martin Golding wrote:Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Re: else indent errorr help

micseydel wrote:
RainbowShibe wrote:As for organized I'm not sure if it's just me who thinks it is or what, it may also be because on linux a tab doesnt equals 4 or 8 spaces but more like 12 and is very hard to see the difference in spaces.

Tabs and spaces are each characters. They're bytes. In Python source code, tabs and spaces are used for the same thing, creating code blocks. But nowhere with any amount of sophistication is there any inherent conversion between one and the other. It is a display option in a very local context. Most modern text editors allow you to say, in terms of display, how wide a tab character should be displayed relative to a space character. I will reiterate because this important: it's all about appearance.

Now that we're talking about display and appearance, what's the issue? The issue is consistency. If you mix tabs and spaces, you end up with garbage looking code sometimes. The solution is to change the editor's settings, right? Well, that's a short-term solution. You'll inevitably have to do it again when you view a file that wants the tab to be a different width. You're setting yourself up for failure The Java standard class files that you have source code to have this inconsistency and it's painful to read. Here is an example in ArrayList.class
Code: Select all
`    public int indexOf(Object o) {   if (o == null) {       for (int i = 0; i < size; i++)      if (elementData[i]==null)          return i;   } else {       for (int i = 0; i < size; i++)      if (o.equals(elementData[i]))          return i;   }   return -1;    }`

This is disgusting and damned difficult to read, not to mention that in rare cases you'll even get code which looks valid (the above looks clearly invalid, so you know to change your editor settings) that you'll read wrong! That can cause literally hours of lost productivity, not to mention trichotillomania.

In Python we have a convention of using just spaces. There are arguments for just tabs, but since the community at large is already using spaces, you have the problem that if you use tabs then anyone who adds to your code will cause the previously mentioned problems and when you add to most code in the wild people will yell at you during code reviews, or worse, they won't notice and that stuff will sneak into a code base and bite someone later.

I'll leave you with a quote as a rule of thumb for how to write your code, with the knowledge that someone might lose hours of their life to your decisions
Martin Golding wrote:Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

This is how it looks for me, its not all that bad.
And as for the part where most people use spaces, I will definetly take that into notice before posting anymore code. Although I would enjoy it if you didnt assume what I will end up with in life.
MLP:FIM <3

RainbowShibe

Posts: 10
Joined: Wed Jan 01, 2014 12:39 am
Location: Somewhere Over The Rainbow

### Re: else indent errorr help

thankyou everyone each of your answers help this code is free to use and completely works now but i have proof if you try to steal it and call it your own i will go to a legal case with it if you want to modify the code at all please notify me at benjaminhernacki@gmail.com
Code: Select all
`import randomquestion = input("do you want random or input (1 = input 2 = random)")if question == 1:   first = input("first")   second = input("second")   third = input("third")   if first >= second >= third:      print third , second , first      print "range" , first - third      print "average" , (third + second + first)/3      print "medain" , second      if third == first:         print "mode" , first      else:         if second == first:            print "mode" , first         else:            if second == third:               print "mode" , second            else:               print "no mode"   else:      if first <= second <= third:         print first , second , third         print "range" , third - first         print "average" , (third + second + first)/3         print "median" , second         if third == first:            print "mode" , first         else:            if second == first:               print "mode" , first            else:               if second == third:                  print "mode" , second               else:                  print "no mode"      else:         if second >= first >= third:            print third , first , second            print "range" , second-third            print "average" , (third + second + first)/3            print "median" , first            if third == first:               print "mode" , first            else:               if second == first:                  print "mode" , first               else:                  if second == third:                     print "mode" , second                  else:                     print "no mode"         else:            if second >= third >= first:               print first , third , second               print "range" , second - first               print "average" , (third + second + first)/3               print "median" , third               if third == first:                  print "mode" , first               else:                  if second == first:                     print "mode" , first                  else:                     if second == third:                        print "mode" , second                     else:                        print "no mode"            else:                                                             if third >= first >= second:                  print second , first , third                  print "range" ,third - second                  print "average" , (third + second + first)/3                  print "median" , first                  if third == first:                     print "mode" , first                  else:                     if second == first:                        print "mode" , first                     else:                        if second == third:                           print "mode" , second                        else:                           print "no mode"               else:                  print "error"else:    first = random.randint(1,900000000000000000)    second = random.randint(1,900000000000000000)    third = random.randint(1,900000000000000000)    if first >= second >= third:        print third , second , first        print "range" , first - third        print "average" , (third + second + first)/3        print "medain" , second        if third == first:         print "mode" , first        else:            if second == first:                print "mode" , first            else:                if second == third:                   print "mode" , second                else:                   print "no mode"    else:        if first <= second <= third:            print first , second , third            print "range" , third - first            print "average" , (third + second + first)/3            print "median" , second            if third == first:                print "mode" , first            else:                if second == first:                    print "mode" , first                else:                    if second == third:                        print "mode" , second                    else:                        print "no mode"        else:            if second >= first >= third:                print third , first , second                print "range" , second-third                print "average" , (third + second + first)/3                print "median" , first                if third == first:                    print "mode" , first                else:                    if second == first:                        print "mode" , first                    else:                        if second == third:                            print "mode" , second                        else:                            print "no mode"            else:                if second >= third >= first:                    print first , third , second                    print "range" , second - first                    print "average" , (third + second + first)/3                    print "median" , third                    if third == first:                        print "mode" , first                    else:                        if second == first:                            print "mode" , first                        else:                            if second == third:                                print "mode" , second                            else:                                print "no mode"                else:                                                                  if third >= first >= second:                        print second , first , third                        print "range" ,third - second                        print "average" , (third + second + first)/3                        print "median" , first                        if third == first:                            print "mode" , first                        else:                            if second == first:                                print "mode" , first                            else:                                if second == third:                                    print "mode" , second                                else:                                    print "no mode"                    else:                        print "error"`
Last edited by micseydel on Fri Jan 03, 2014 6:42 am, edited 1 time in total.
Reason: Code tags, lock.
funky9819

Posts: 2
Joined: Wed Jan 01, 2014 5:31 pm

### Re: else indent errorr help

RainbowShibe wrote:This is how it looks for me, its not all that bad.

micseydel wrote:Now that we're talking about display and appearance, what's the issue? The issue is consistency. If you mix tabs and spaces, you end up with garbage looking code sometimes. The solution is to change the editor's settings, right? Well, that's a short-term solution. You'll inevitably have to do it again when you view a file that wants the tab to be a different width. You're setting yourself up for failure The Java standard class files that you have source code to have this inconsistency and it's painful to read. Here is an example in ArrayList.class [...]

(New emphasis added.) My claim was not about every single file you open. You can and will have files for which it's not a problem. I believe I was quite clear about this. But in the long run it's a problem. In the Java code I posted, I could modify my settings to have it look proper. If I were to do so, then whatever code looked proper using the default settings would then look bad. There is no winning.

RainbowShibe wrote:And as for the part where most people use spaces, I will definetly take that into notice before posting anymore code. Although I would enjoy it if you didnt assume what I will end up with in life.

I make no assumptions. My advice applies to if you continue programming. If you do not, then you needn't take any advice you find on this site. If you do continue programming, you'll see what I mean even if you decide to be stubborn, which you're entitled to be, but it does no one any good.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Re: else indent errorr help

I make no assumptions. My advice applies to if you continue programming. If you do not, then you needn't take any advice you find on this site. If you do continue programming, you'll see what I mean even if you decide to be stubborn, which you're entitled to be, but it does no one any good.

Im not really stubborn ._., I even said I would take it for advice.
I also only program for relaxing, but I do like them to work.
But i would say telling me i will end uo with tricholimania if i continued like that is an assumtion.
Sorry if you thought I was intending my last post to be a start of an arguement, but if it sounds like it, please accept this appology. I dont like making enemies in the first week. I really dont like posting so much in one thread anyways >.> it feels like Im spamming.
MLP:FIM <3

RainbowShibe

Posts: 10
Joined: Wed Jan 01, 2014 12:39 am
Location: Somewhere Over The Rainbow