15,878,316 members
See more:
Hello coding community!
I am 9 years old and love programming in Python and this is my first time posting - so wish me luck!
I have just written a simple calculator - in Python - and I mainly struggle with concentration on writing the actual code (normally I spend ages printing long lines telling the user what to do - I should do that the end!). I am also trying to do this with as little help as possible to see if I can independently (on my own) code. But anyway, I keep on receiving this indentation error:

```Traceback (most recent call last):
File "python", line 9
TabError: inconsistent use of tabs and spaces in indentation```

I would be grateful for any help I can get.
This is my whole code:

Python
```#A simple calculator - I am doing this entirely without help and nonsanse such as printing, so here goes!
def calculator(x, y, z):
operation = input("a = Add, s = Subtract, m = Multiply, d = Divide")
if operation == "a":
x = input("First number:")
y = input("Second number:")
other = input("Any other numbers?")
elif other == "y":
return x + y +  z
else:
return x + y

if operation == "s":
x = input("First number:")
y = input("Second number:")
return x - y
if operation == "m":
x = input("First number:")
y = input("Second number:")
return x * y
if operation == "d":
x = input("First number:")
y = input("Second number:")
return x / y

print (calculator)

calculator(x, y)```

What I have tried:

I have tried putting the
Python
`elif`
statement inside the
Python
`if`
, and same with the
Python
`else`
statement.
Posted
Updated 11-Jan-21 6:40am

## Solution 1

The elif and else block is to check the input for "other", so it should be an if else block and indented like the "other" variable.
You could have use elif for other "operation" values as they belong to the same chain of flow.
One last point, it serves no purpose to use a function in your case, so replace all the return statements with print with do.

v7

## Solution 2

Try this
Python
```def calculator(x, y, z):
operation = input("a = Add, s = Subtract, m = Multiply, d = Divide")
if operation == "a":
x = input("First number:")
y = input("Second number:")
other = input("Any other numbers?")
if other == "y":     # this is a new if block
return x + y +  z
else:
return x + y

elif operation == "s":     # this continues the "if operation ..." above
x = input("First number:")
y = input("Second number:")
return x - y
elif operation == "m":     # so does this
x = input("First number:")
y = input("Second number:")
return x * y
elif operation == "d":     # so does this
x = input("First number:")
y = input("Second number:")
return x / y

print (calculator)

calculator(x, y)```

You have also declared `calculator` as taking three parameters (`x,y,z`), but then you ask the user to type them in. Also your call at the bottom of the code only sends `x` and `y`.

However, I have to say, for a 9 year old that is some pretty good code, keep it up.

Member 12971412 28-Jan-17 7:02am
Hey, thanks. That's just made my day a whole lot better!

## Solution 4

By the way all the solution above does not work. You can't declare arguments call for function that is going to get user input. Because to call that function you have to pass argument for it so it doesn't throw error.

Secondly, if you need a string input you call raw_input function. If you need integer number, you call the input function. This is the working code of that calculator and I wrote it as easiest to read as possible. Have fun and good luck If you need programming help, look for my articles. I write for people that just learning to the very expert one. It take me a week to go through one subject but if you read my article you can find out which programming language which suit you.

Here is the working program. With one loop of built in error check to show you how it is done.
Python
```def calculator():

operation = raw_input("a = Add, s = Subtract, m = Multiply, d = Divide:")
while (operation is not "a" and operation is not "s" and operation is not "m" and operation is not "d" and operation is not "q"):
print("Incorrect input, please try again. Type q to quit" )
operation = raw_input("a = Add, s = Subtract, m = Multiply, d = Divide:")
if operation is "q":
return;

if operation is "a":
x = input("First number:")
y = input("Second number:")
other = raw_input("Any other numbers?")
if other == "y":
return x + y + z
else:
return x + y

if operation is "s":
x = input("First number:")
y = input("Second number:")
return x - y
if operation == "m":
x = input("First number:")
y = input("Second number:")
return x * y
if operation is "d":
x = input("First number:")
y = input("Second number:")
return x / y

a = calculator()
print(a)```

## Solution 5

Quote:
I keep on receiving this indentation error:

Traceback (most recent call last):
File "python", line 9
TabError: inconsistent use of tabs and spaces in indentation

Message is rather explicit, it tell you that line 9 start with a mix of tabs and spaces. PHP can only deal with 1 kind of them at a given time.
Java
```<tab>elif other == "y":

Professional text editors can make visible those chars.
Otherwise, put the cursor on left and use right arrow, if cursor moves 1 position, it is a space, if cursor moves to next column which is multiple of 4, it is a tab.