简体   繁体   中英

TabError: inconsistent use of tabs and spaces in indentation | Coding a simple calculator

I'm trying to code a simple calculator.

Below is the Updated code. But still same error.

running = True   
while running:
        print("1 Addition \
            2 Subtraction \
            3 Multiplication \
            4 Division \
            5 remainder \
            6 Power of \
            7 Quit")

        O = int(input('What Operaton you want to do ? '))
        F = float(input('Enter first number: '))
        S = float(input('Enter Second number: '))

        if O == 1:
            R = F + S
            print(F,'+',S,'=',R)
        elif O == 2:
            R = F - S
            print(F,'-',S,'=',R)
        elif O == 3:
            R = F * S
            print(F,'*',S,'=',R)
        elif O == 4:
            R = F / S
            print(F,'/',S,'=',R)
        elif O == 5:
            R = F % S
            print(F,'%',S,'=',R)
        elif O == 6:
            R = F ** S
            print(F,'**',S,'=',R)
        else:
            print('Quit')
            running = False

And while running I'm facing the Below error.

$/usr/local/bin/python3.7 file1.py File "file1.py", line 20 R = F - S ^ TabError: inconsistent use of tabs and spaces in indentation

You're indenting your while statement unnecessarily.

running = True   
    while running:

should be:

running = True   
while running:

There is another problem though:

Instead of:

else O == 7:
    print('Quit')
    running = False

You should write:

else:
    print('Quit')
    running = False

else doesn't take any argument. It is simple the set of statements chosen when no if or elif condition is true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM