Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

limit to multiples of 5  RSS feed

 
John Swain
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a quick question. how would you limit a user to only input multiples of 5 (5 - 100).
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a while loop that prompts the user again if they input
an incorrect number.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you were the Web Designer From Hell (who seems to design most e-commerce sites) you'd have a dropdown list with 5,10,15,20 ... 100

Sorry about that rant. If it's a console application, the first answer was much better. Look up the % operator if you aren't already familiar with it.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stan, you need to think outside the box. See, I'd give the user a dropdown with 1, 2, ... 100, and when they submitted the form with 18 selected, I'd return an error page telling them to choose a number evenly divisible by 5. Hitting the back button would of course clear all of their input fields.

Oooh, is it hot in here or is it just me?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And start all the values in the dropdown with leading zeros 001, 002, 099. To select 95 from the keyboard, hit the 0 key 95 times.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not worthy! The force is strong in you, master.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!