Does anyone have a suggestion for a command line program I could make?
Since I finished the programming on my website I have been at a loss of what to do, and I want some content before I release it (which is good, i think). Any ideas?
Make a simple four-function calculator program or something.
[QUOTE={ABK}AbbySciuto;25797391]Make a simple four-function calculator program or something.[/QUOTE]
Done
[code]
import sys
while True:
print "Simple Calculator Program"
print "Type help for allowed expressions"
print "Type exit to exit"
usrin = raw_input("> ")
if usrin.lower() == "help":
print """ Allowed Expressions:
Addition: +
Subtraction: -
Multiplaction: *
Division: /
Exponent: ^
Format Like So:
num1 exp num2
Example:
5 * 2
"""
elif usrin.lower() == "exit":
break
else:
usr2 = usrin.replace(" ", "")
if usr2.find("+") != -1:
exp = usr2.find("+")
result = int(usr2[:exp]) + int(usr2[exp+1:])
print result
print "\n"
elif usr2.find("-") != -1:
exp = usr2.find("-")
result = int(usr2[:exp]) - int(usr2[exp+1:])
print result
print "\n"
elif usr2.find("*") != -1:
exp = usr2.find("*")
result = int(usr2[:exp]) * int(usr2[exp+1:])
print result
print "\n"
elif usr2.find("/") != -1:
exp = usr2.find("/")
result = int(usr2[:exp]) / int(usr2[exp+1:])
print result
print "\n"
elif usr2.find("^") != -1:
exp = usr2.find("^")
result = int(usr2[:exp]) ** int(usr2[exp+1:])
print result
print "\n"
else:
print "Invalid Expression"
print "\n"
[/code]
Now add support for Reverse Polish Notation.
[QUOTE=Rupert;25798242]Now add support for Reverse Polish Notation.[/QUOTE]
I'm not even going to look that up.
Get a textbook, they have tons of example practice problems in there.
[QUOTE=W00tbeer1;25798862]Get a textbook, they have tons of example practice problems in there.[/QUOTE]
But Christmas isn't for another 2 months!
Text RPG.
ASCII 2D Minecraft.
I want Creepers.
Go!
[QUOTE=supersnail11;25798328]I'm not even going to look that up.[/QUOTE]
Well there's your problem if you want to become a good programmer.
[QUOTE=Matthew0505;25802413]Why? RPN is the easiest type of calculator to program[/QUOTE]
This. If I can write an RPN calculator in assembly as a beginner with little effort, then it should be quite a straight forward task for anyone in a high level language.
[QUOTE=Matthew0505;25802413]
Oh wait, this is the guy that thinks Java is interpreted and C is a port of assembly[/QUOTE]
....
Now that just isn't nice....
[editline]2nd November 2010[/editline]
[QUOTE=Siemens;25802667]This. If I can write an RPN calculator in assembly as a beginner with little effort, then it should be quite a straight forward task for anyone in a high level language.[/QUOTE]
What is the benifit of RPN over regular?
RPN can calculate something like "(2/4+6)*(73.7^2-1123)-12341+(-45*6)"
[QUOTE=sim642;25807234]RPN can calculate something like "(2/4+6)*(73.7^2-1123)-12341+(-45*6)"[/QUOTE]
But I can do that too....
Makes it easier?
[QUOTE=dag10;25799226]ASCII 2D Minecraft.
I want Creepers.
Go![/QUOTE]
I think you mean ASCII 2D [i]infiniminer[/i]
And no.
[QUOTE=Matthew0505;25802413]Oh wait, this is the guy that thinks Java is interpreted and C is a port of assembly[/QUOTE]
Wait, what?
[QUOTE=BlkDucky;25815234]Wait, what?[/QUOTE]
Different thread
[QUOTE=Matthew0505;25820561]Basically this is how it works
User inputs a number: Push it onto the stack
User inputs an operator:
+ - temp = pop(); push(pop() + temp)
- - temp = pop(); push(pop() - temp)
* - temp = pop(); push(pop() * temp)
/ - temp = pop(); push(pop() / temp)
Wikipedia has a shunting-yard algorithm that turns infix (eg. 1 + 2 * 3 + 4) into RPN/postfix (eg. 1 2 3 * + 4 +)[/QUOTE]
Temp is only needed for the non-commutative operations.
You can just do push(pop() + pop()) for add and mul
Sorry, you need to Log In to post a reply to this thread.