-4
coin1 = raw_input("Coin1: ")
while coin1 != (10, 20, 50, 100):
    print "That is not a correct coin value"
    coin1 = raw_input("Coin1: ")

This bit of code should ask the user to input a value for the variable "coin1", check if the value is equal to 10, 20, 50, or 100, and if it is not equal to any of these numbers, it should tell you that it is an "incorrect coin value" and ask you to input another value for the variable "coin1".

It asks me to input a value, but no matter what I type, it doesn't accept the value, it just tells me that it is an "incorrect coin value".

I've been trying to make it work for hours, I have literally no idea what's wrong, and I'm a beginner to Python. Can any of you guys help out?

Alex Riley
  • 169,130
  • 45
  • 262
  • 238
  • 3
    Put your code inline in your post and not a link – EdChum Aug 13 '14 at 13:15
  • 1
    A screenshot?! Code is text, please provide it as such. My guess is you're comparing the string from `raw_input` to an integer. – jonrsharpe Aug 13 '14 at 13:16
  • @jonrsharpe: better... a tuple. – Wooble Aug 13 '14 at 13:16
  • http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values is what you should read. Didn't close as duplicate because it's strictly off-topic with the code in a screenshot off-site. – Wooble Aug 13 '14 at 13:19
  • Sorry, I'm new to the site. Next time I'll be sure to provide the code in text. Wooble, I thought it would be easier to ask my own question rather than find the answer elsewhere. Sorry. – user3937516 Aug 13 '14 at 14:04
  • @user3937516 easier for you, sure, but that's not a particularly good reason. Please read http://stackoverflow.com/help/how-to-ask and http://meta.stackoverflow.com/q/260648/3001761 – jonrsharpe Aug 14 '14 at 22:51

2 Answers2

1

The user's input will be treated as a string by Python, not an integer. With != you're also comparing coin1 with a tuple of int values which it will never be equal to (again, coin1 will be a string).

This checks whether the user's input coin1 is one of the accepted coin values:

while coin1 not in ("10", "20", "50", "100"):
    ...
Alex Riley
  • 169,130
  • 45
  • 262
  • 238
0

Change this:

while coin1 != (10, 20, 50, 100)

To this:

while coin1 not in ['10', '20', '50', '100']
barak manos
  • 29,648
  • 10
  • 62
  • 114