Python

Paul Rubin phr-n2003b at NOSPAMnightsong.com
Thu Feb 6 22:46:34 EST 2003


phrogeeb at hotmail.com (Uri) writes:
> Ok, so Python vets I bet are already seeing what my problem is. I ask
> for the numbers with the syntax:     r = input("r?")
> 
> My problem is that r is a percentage (in my program, I tell the user
> to represent 4% as .04).  When I run the program, it says that there's
> no way to deal with a double or something to that effect. But I also
> read that there's no way to type a variable, that they are
> "dynamically typed". Well, that doesn't work here.

The problem is the input function returns a string, not a float.
To convert a string to a float, use the "float" function, like

    e = float("2.71828")

Also, you should use raw_input rather than input, to get exactly
what the user types.  So you'd write your example

    r = float(raw_input("r? "))




More information about the Python-list mailing list