← Back to all posts
13
3 line calculator

This is just THREE LINES. I counted.

Commentshotnewtop
2

did you try

while True: print(eval(input("Type your Calculations: ")))

should work in one line

1

I see 2 lines...

1

This is very insecure though.

1

4 lines, you mean.

4

@SwaagatB Made it in 1 line:

while True: print(eval(input('\n')))
1

How about 90 / 0?

1
1

@SwaagatB Well then you should have bothered to add some input validation

1

@SwaagatB I wonder if you could add some error checking. Once you type something like 1 / 0 it breaks the calculator. Maybe you could make it say something like "hey, that's not valid math!"

1

@aliloua Yeah but, calculator in 10 lines of code doesn't sound as impressive

1

It's four lines technically, but you can make it two. Or one if you change what to output. 🙃