On Wed, Oct 24, 2012 at 7:15 AM, Morten Engvoldsen <[email protected]> wrote:
>
> I am facing issue with input() of Python 2.7
> ....
>
> fat_grams = input("How many grams of fat are in one serving? ")
> total_calories = input("How many total calories are in one serving? ")
> print("A food product having {0} fat grams and {1} total
> calories",fat_grams, total_calories);
> return;
Avoid using input() in Python 2.x. It evaluates arbitrary expressions
that can be a security risk at worst, but at least a source of bugs.
Instead use raw_input(). This returns an unevaluated string. You can
convert it to a number with int():
>>> grams = int(raw_input("How many grams? "))
How many grams? 28
>>> grams
28
Also, "print" is a statement in 2.x; you don't call() it as a
function, not unless you import the print() function from __future__:
>>> print # print an empty line
>>> from __future__ import print_function
>>> print # now it's a function
<built-in function print>
Finally, you don't have to terminate any lines with a semicolon.
Python's grammar allows it, but it's not idiomatic style.
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor