On 02/07/2016 01:16, DFS wrote:
On 7/1/2016 5:34 AM, Pierre-Alain Dorange wrote:
More reduced :
--
u=raw_input('Enter calculation:")
print eval(u)
--
works and compute :
1+2+3+4-1+4*2
2+3.0/2-0.5
Perform better and shorter, but l
Op 01-07-16 om 15:52 schreef Steven D'Aprano:
> On Fri, 1 Jul 2016 10:25 pm, Christopher Reimer wrote:
>
>> For my BASIC interpreter, each line of BASIC is broken this way into
>> tokens.
> [...]
>> By using * to unpack the split line, my program no longer crashes and no
>> try/except block is need
DFS wrote:
>
> 2 lines? Love it!
>
> But apparently eval==evil.
>
> http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
>
> I bet you get hammered about it here on clp.
It was a software to be deploy, it was just for educational purpose.
--
Pierre-Alain Dorange
Steven D'Aprano writes:
> On Fri, 1 Jul 2016 10:25 pm, Christopher Reimer wrote:
>
>> For my BASIC interpreter, each line of BASIC is broken this way into
>> tokens.
> [...]
>> By using * to unpack the split line, my program no longer crashes and no
>> try/except block is needed to work around the
> On Jul 1, 2016, at 6:52 AM, Steven D'Aprano wrote:
>
>> On Fri, 1 Jul 2016 10:25 pm, Christopher Reimer wrote:
>>
>> For my BASIC interpreter, each line of BASIC is broken this way into
>> tokens.
> [...]
>> By using * to unpack the split line, my program no longer crashes and no
>> try/except
On Fri, 01 Jul 2016 23:52:45 +1000, Steven D'Aprano wrote:
> On Fri, 1 Jul 2016 10:25 pm, Christopher Reimer wrote:
>
>> For my BASIC interpreter, each line of BASIC is broken this way into
>> tokens.
> [...]
>> By using * to unpack the split line, my program no longer crashes and
>> no try/excep
On Fri, 1 Jul 2016 10:25 pm, Christopher Reimer wrote:
> For my BASIC interpreter, each line of BASIC is broken this way into
> tokens.
[...]
> By using * to unpack the split line, my program no longer crashes and no
> try/except block is needed to work around the crash. A later line of code
> wil
Christopher Reimer writes:
>> On Jul 1, 2016, at 5:46 AM, Jussi Piitulainen wrote:
>>
>> Christopher Reimer writes:
>>
>>> For my BASIC interpreter, each line of BASIC is broken this way into
>>> tokens.
>>>
>>> line_number, keyword, *expression = line.split(' ', 2)
>>>
>>> For a line like 10
> On Jul 1, 2016, at 5:46 AM, Jussi Piitulainen
> wrote:
>
> Christopher Reimer writes:
>
>> For my BASIC interpreter, each line of BASIC is broken this way into
>> tokens.
>>
>> line_number, keyword, *expression = line.split(' ', 2)
>>
>> For a line like 10 PRINT "HELLO, WORLD!", this works
Chris Warrick wrote:
> > More reduced :
> > --
> > u=raw_input('Enter calculation:")
> > print eval(u)
> > --
> > works and compute :
> > 1+2+3+4-1+4*2
> > 2+3.0/2-0.5
> >
> > Perform better and shorter, but less educationnal of cour
Christopher Reimer writes:
> For my BASIC interpreter, each line of BASIC is broken this way into
> tokens.
>
> line_number, keyword, *expression = line.split(' ', 2)
>
> For a line like 10 PRINT "HELLO, WORLD!", this works as expected.
>
> For a line like 20 END, which doesn't have a third elemen
> On Jun 30, 2016, at 11:42 PM, Jussi Piitulainen
> wrote:
>
> DFS writes:
>
>> Here's a related program that doesn't require you to tell it what type
>> of operation to perform. Just enter 'num1 operator num2' and hit
>> Enter, and it will parse the entry and do the math.
>>
>> -
On 1 July 2016 at 11:34, Pierre-Alain Dorange
wrote:
> DFS wrote:
>
>> Here's a related program that doesn't require you to tell it what type
>> of operation to perform. Just enter 'num1 operator num2' and hit Enter,
>> and it will parse the entry and do the math.
>>
>> -
DFS wrote:
> Here's a related program that doesn't require you to tell it what type
> of operation to perform. Just enter 'num1 operator num2' and hit Enter,
> and it will parse the entry and do the math.
>
> ---
> ui=raw_input('Enter calculation to p
On 1 July 2016 at 05:08, Elizabeth Weiss wrote:
> while True:
> print("Options:")
> print("Enter 'add' to add two numbers")
> print("Enter 'subtract' to subtract two numbers")
> print("Enter 'multiply' to multiply two numbers")
> print("Enter 'divide' to div
DFS writes:
> Here's a related program that doesn't require you to tell it what type
> of operation to perform. Just enter 'num1 operator num2' and hit
> Enter, and it will parse the entry and do the math.
>
> ---
> ui=raw_input('Enter calculation to pe
On 06/30/2016 09:08 PM, Elizabeth Weiss wrote:
> while True:
> print("Options:")
> print("Enter 'add' to add two numbers")
> print("Enter 'subtract' to subtract two numbers")
> print("Enter 'multiply' to multiply two numbers")
> print("Enter 'divide' to divide two numb
while True:
print("Options:")
print("Enter 'add' to add two numbers")
print("Enter 'subtract' to subtract two numbers")
print("Enter 'multiply' to multiply two numbers")
print("Enter 'divide' to divide two numbers")
print("Enter 'quit' to end the prog
18 matches
Mail list logo