![]() |
| ||
| Python Beginner Help (Calculator) Hello Everyone, I just joined here hoping to increase my knowledge at python. I have been beginning to learn this language as of yesterday. I have decided that if I really want to increase my knowledge I should start on a project. Well here is my first project, a simple calculator. But for whatever reason when I run the program I'm getting some strange errors... Whatever help and advice you guys could give me would be most appreciated! #Calculator Test1 Thanks, Inkcoder |
| ||
| Re: Python Beginner Help (Calculator) THe line: op = input(">")Takes the input AND evaluates it. That means inputing "1" results in eval("1") which is int("1'). Putting in something like "a" results in the interpreter looking for a name "a" and not finding it. For the beginning I recommend to use: op=raw_input(">") |
| ||
| Re: Python Beginner Help (Calculator) First, welcome to the forum! What 'slate' is really telling you is that input() is for numbers and raw_input() is for strings. Using input() has certain risks since you can also enter a command and it will excute it. Anyway, if you want to use op = input(">") then op will not be a string and you have to use this if statement if op == 1: In the matter of fact, input() allows you to create this very simple calculator, since it evaluates mathematical expressions directly: print "At the >> prompt enter x op y" |
| All times are GMT -4. The time now is 8:40 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC