Limit between 0 and 100

Benjamin Kaplan benjamin.kaplan at case.edu
Sat Oct 25 17:17:52 EDT 2008


On Sat, Oct 25, 2008 at 4:42 PM, <chemicalclothing at temple.edu> wrote:

> Hi. I'm very new to Python, and so this is probably a pretty basic
> question, but I'm lost. I am looking to limit a float value to a
> number between 0 and 100 (the input is a percentage).
>
> I currently have:
>
> integer = int()
> running = True
>
> while running:
>  try:
>    per_period_interest_rate = float(raw_input("Enter per-period
> interest rate, in percent: "))
>    break
>  except ValueError:
>    print "Please re-enter the per-period interest rate as a number
> between 0 and 100."
>
>
> I also have to make sure it is a number and not letters or anything.
>
> Thanks for the help.
>
> James
>
> P.S. I don't understand a lot of what I have there, I got most of it
> from the beginning tutorials and help sections. I have never
> programmed before, but this is for a school assignment.
> --


look up conditionals (specifically if statements) in the Python tutorial. If
you still can't figure it out, ask on the Python Tutor list. This list is
for questions about python, not for questions about how to program.

>
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081025/95a88991/attachment-0001.html>


More information about the Python-list mailing list