You are not logged in.
Hello.
I write (with some help-Thanks Xyne) a very simple calculator.
It only need python package to work.
Here it is.
It could do base thing's.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
number1 = int(raw_input('Write a number: '))
number2 = int(raw_input('Write a number nr.2: '))
znak = raw_input('What to do?')
if znak == '+':
print number1 + number2
elif znak == '-':
print number1 - number2
elif znak == '*':
print number1 * number2
elif znak == '/':
print number1 / number2
elif znak == '**':
print number1 ** number2
elif znak == '//':
print number1 // number2
else:
print "I don't know what to do with " + znak
Any suggestions or ideas?
Last edited by SpeedVin (2009-09-26 09:41:17)
Shell Scripter | C/C++/Python/Java Coder | ZSH
Offline
Why not just 'python' in terminal?
$ python
>>> 2+2
4
>>> 2*2
4
>>> 2/2
1
>>> 2**2
4
Sorry if I misunderstood...
This silver ladybug at line 28...
Offline
How about:
alias calc='bc -l <<<'
$ calc 2+2
You need to install an RTFM interface.
Offline
How about:
alias calc='bc -l <<<'
$ calc 2+2
I how to add this alias to my .abshrc or to the code?
Why not just 'python' in terminal?
$ python
>>> 2+2
4
>>> 2*2
4
>>> 2/2
1
>>> 2**2
4Sorry if I misunderstood...
I writed it for newbies that don't know any command of python but have it installed becouse it's dep for another package
Shell Scripter | C/C++/Python/Java Coder | ZSH
Offline
Nice beginner's program there SpeedVin! Keep it up. Python rocks.
How about:
alias calc='bc -l <<<'
$ calc 2+2
Or pacman -S calc.
Offline
Nice beginner's program there SpeedVin! Keep it up.
Python rocks.
anrxc wrote:How about:
alias calc='bc -l <<<'
$ calc 2+2
Or pacman -S calc.
Thanks.
I think too that Python Rocks.
Last edited by SpeedVin (2009-09-26 08:44:23)
Shell Scripter | C/C++/Python/Java Coder | ZSH
Offline
Update
Calculator now can floor division.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
number1 = int(raw_input('Write a number: '))
number2 = int(raw_input('Write a number nr.2: '))
znak = raw_input('What to do?')
if znak == '+':
print number1 + number2
elif znak == '-':
print number1 - number2
elif znak == '*':
print number1 * number2
elif znak == '/':
print number1 / number2
elif znak == '**':
print number1 ** number2
elif znak == '//':
print number1 // number2
else:
print "I don't know what to do with " + znak
Last edited by SpeedVin (2009-09-26 12:33:51)
Shell Scripter | C/C++/Python/Java Coder | ZSH
Offline
speedvin, your code works and it is always good to learn a language and start with such calc program gives the inner of structured programming. I have this simple function in .bashrc and serves the purpose.
function calc() { echo "scale=4;$*" | bc; }
calc 10/3+6 gives 9.0303
Offline
speedvin, your code works and it is always good to learn a language and start with such calc program gives the inner of structured programming. I have this simple function in .bashrc and serves the purpose.
function calc() { echo "scale=4;$*" | bc; }
calc 10/3+6 gives 9.0303
Thanks kgas
I updated calc for a help message (run it with -h).
Anyone can find current code at my github site.
Shell Scripter | C/C++/Python/Java Coder | ZSH
Offline