[Tutor] dangers of input()
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Tue Jul 20 20:05:54 CEST 2004
On Tue, 20 Jul 2004, Dick Moores wrote:
> I was thinking of using input() instead of raw_input in my Frac.py
> (posted yesterday). This would enable the user to enter things such as
> "4**-3". Am I correct in assuming that this would be impossible to do
> without using input()? If so, I may go ahead with input()--I'm the only
> user, after all.
Hi Dick,
Yup, that's right:
###
>>> value = input("enter an expression: ")
enter an expression: 2**3 + 4**2 + 3**1
>>> value
27
>>>
>>>
>>> value = raw_input("enter an expression: ")
enter an expression: 2**3 + 4**2 + 3**1
>>> value
'2**3 + 4**2 + 3**1'
###
Hope this helps!
More information about the Tutor
mailing list