[Courses]Need a little help with extremely basic Python programming

Jason Kappel the__taco_ at hotmail.com
Thu Aug 21 14:11:29 EST 2003


   I have a quick question about the program in question. I wrote a
   version that not only adds up to 100, but won't let the user go over,
   and now I'm looking for a way to check if the input is actually a
   number, so I don't get an error when text is entered as an input. Is
   there a function to check if an input is either an integer or floating
   point?

   #this takes number inputs from the user untill the sum reaches 100
   sum = 0.0
   while (sum < 100):
       remaining = 100.0-sum
       print "Please choose a number no larger than",remaining
       number = input ("> ")
       sum = sum+number
       while (number > remaining): #while input too large, subtract and
   try again
           sum = sum-number
           print "That was bigger than",remaining,"try again"
           number = input ("> ")
           sum = sum+number
   print "Good for you! You can add to",sum


   I have a quick question
     _________________________________________________________________

   [1]MSN 8: Get 6 months for $9.95/month.

References

   1. http://g.msn.com/8HMFENUS/2728??PS=


More information about the Courses mailing list