## Inputs should be multiples of 12

This is the place for queries that don't fit in any of the other categories.

### Inputs should be multiples of 12

I'm totally new to python and i'm making a program using python that will ask the user to enter the number of chocolates they would like to purchase. But the problem is how can i get the user to input the number of chocolates in multiples of 12, so basically a dozen. If the input is not a multiple of 12 then ask them to re-enter the number of chocolates in multiples of 12. Please help me.
Last edited by Mekire on Fri Apr 04, 2014 4:24 am, edited 1 time in total.
Reason: First post lock.
pc10015

Posts: 8
Joined: Fri Apr 04, 2014 4:14 am

### Re: Inputs should be multiples of 12

You are going to need a while loop where you get the input. THen check if the input is evenly divisible by twelve (probably using the modulus operator). If this is satisfied, break out of the loop.

This is simple enough, but I would like to see an attempt before I hand you any code.
-Mek
New Users, Read This
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Describe your problem; not your chosen solution.
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Re: Inputs should be multiples of 12

Mekire Thank you for your advice. It worked. Here is what i got.

Code: Select all
`numberChocolate=0while numberChocolate!="q":    numberChocolate=int(input("Enter number of chocolates you would like to buy:"))    if numberChocolate%12:        print("Enter the number of chocolate in a dozen.")    else:        print("Thank you")        break`
pc10015

Posts: 8
Joined: Fri Apr 04, 2014 4:14 am

### Re: Inputs should be multiples of 12

Pretty good. You still need to add some error checking though (probably with try/except). Currently your program will crash if it is given anything other than an integer. Even 'q' which you intended to quit the loop actually crashes the program.

-Mek
New Users, Read This
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Describe your problem; not your chosen solution.
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

Return to General Coding Help

### Who is online

Users browsing this forum: No registered users and 4 guests