Apologies for basic nature of this query - this is almost my first Python script.
I want the user to enter a two character string corresponding to a playing card (eg 2c, 3s) and for the program to check two things: first, whether it's in the list of valid cards, and second, whether that card has already been entered. If either condition is failed, I want the user to be prompted to re-enter the card. What I have written does each of those things, but it doesn't do them simultaneously - eg, if the card is invalid, the user is prompted, but if the re-entered card is already on the list, no prompt occurs. I can't see how to get both things tested at once.
Anyway, here is what I have:
posscards=["ac",
"2c",
"3c",
"4c",
"5c" #and so on]
for x in range(0, decksize):
answer=raw_input("next card? ")
while answer not in posscards:
answer = raw_input("not a possible card - try again: ")
while answer in deck1:
answer = raw_input ("you've already had that one - try again: ")
deck1.append(answer)
postcardslist instead of writing it out manually. Then you only need to write 13+4 values instead of 13*4, and you can write those 13 values as just a 13-character string. For example,posscards = [value+suit for suit in 'cshd' for value in 'a23456789tjqk']Even if you don't understand that nested list comprehension (which you probably don't), you should be able to write it as a 4-lineforstatement.