0

I am trying to solve this problem many times but I am not able to solve i tried everything but it shows error message everytime

a=int(input('enter the first number')) #we ask for input
b=int(input('enter the second number'))
while True:
    choice=int(input('enter the number corresponding to the operation you want to \nperform \n1)addition \n2)subtraction \n3)multiplication \n4)division '))
    #we ask for the user choice
    if choice==1:  #if the user opts for addition
        addition=a+b
        print(f'the addition of the 2 numbers is {addition} ') #ans
        ans=input('want to try another operation? yes or no')
        if ans=='yes':  #if the user whishes to use another operation
            continue
        else:  #if the user opts out
            print('thank you for using')
            break
    elif choice==2:
        subtraction=a-b #same for others but diffrent opperation

        print(f'the subtraction of the 2 numbers is {subtraction} ')
        ans=input('want to try another operation? yes or no')
        if ans=='yes':
            continue
        else:
            print('thank you for using')
            break
    elif choice==3:
        multiplication=a*b

        print(f'the multiplication of the 2 numbers is {multiplication} ')
        ans=input('want to try another operation? yes or no')
        if ans=='yes':
            continue
        else:
            print('thank you for using')
            break
    else:
        division=a//b
        remainder=a%b
        print(f'the division of the 2 numbers is {division} \nand the remainder is{remainder} ')
        ans=input('want to try another operation? yes or no')
        if ans=='yes':
            continue
        else:
            print('thank you for using')
            break   


the error message is

File "calc_of_2_nos.py", line 15

break ^

IndentationError: unindent does not match any outer indentation level

I don't know how to solve this problem I think I have indentated it perfectly four spaces

Ram Pandey
  • 23
  • 9

2 Answers2

1

This happens to me in Sublime Text sometimes if I mix up tabs and spaces. I am answering specifically for Sublime Text because that is what you say you are using in the comments.

In Sublime Text, when you highlight whitespace you can actually see if it is a tab or a space, like this:

SublimeText

Notice the two arrows on the left. Where you see dots, there are spaces, and where you see lines, there's a tab.

To make your spacing consistent, I recommend that you either go back through manually and delete and then manually and consistently re-indent your code, or use a linter to redo the indentation. Sublime Text provides some tools for this (view -> indentation -> *), and tools exist online.

Another trick in Sublime Text that can help is to search the file for tabs and replace them with (for spaces).

Max von Hippel
  • 2,856
  • 3
  • 29
  • 46
  • 1
    this worked!! so now I am using indention as spaces or i should use indention as tabs? – Ram Pandey May 29 '18 at 18:36
  • The question of whether to use tabs or spaces is one of personal style. It is the topic of [extensive](https://stackoverflow.com/questions/119562/tabs-versus-spaces-in-python-programming) [conversation](https://softwareengineering.stackexchange.com/questions/57/tabs-versus-spaces-what-is-the-proper-indentation-character-for-everything-in-e) as well as [popular media/culture](https://www.youtube.com/watch?v=SsoOG6ZeyUI). Do whatever you think is cooler :) – Max von Hippel May 29 '18 at 18:38
0

I ran it!

I could not find any error.You might want to add a newline after division in your menu choice, else its perfect!

Shiny
  • 67
  • 10
  • Restarting your kernel helps sometimes. I know that is obvious and lame but maybe! – Shiny May 29 '18 at 18:07
  • then why is it showing an error in machine? i am using command prompt – Ram Pandey May 29 '18 at 18:09
  • What version are you using? Python 2 or 3? – Shiny May 29 '18 at 18:09
  • Hi shiny, I don't think this counts as an answer. Also, you should always include actual text, rather than screenshots of text. – Max von Hippel May 29 '18 at 18:10
  • 1
    I am using Jupyter Notebook. I can try using command prompt. Let me get back to you. – Shiny May 29 '18 at 18:11
  • @MaxvonHippel: True. But this was just to show him that it runs, it is an output screenshot. Apologies, I am an audit background girl. Will keep that in mind. – Shiny May 29 '18 at 18:13
  • Shiny, it's fine, you're providing useful feedback, but it would be better in a case like this to comment rather than answer. That way the original poster can see that the problem is not with the code but (most likely) with their build rule in Sublime Text or their dev environment, and provide more information - which can then be used to actually answer the question. – Max von Hippel May 29 '18 at 18:24
  • 2
    @MaxvonHippel: I need 50 rep to do that! :( – Shiny May 29 '18 at 18:37
  • Gotcha! Well, I would just leave this answer, and in the future when you have more rep try to keep the general SO guidelines/documentation in mind in terms of when to comment vs answer. Have fun Stack-Overflowing :) – Max von Hippel May 29 '18 at 18:39
  • Thanks for the feedback! I will keep this in mind :) – Shiny May 29 '18 at 18:41