Reputation: 3
This is my first question on Stack and I am really hoping someone else has had this same problem and can help me.
I have written the below code using Python 3.7.6 that randomly picks a card suit and a corresponding value based on a dict I have built. This code was working absolutely fine yesterday and the day before, however, today the random_number variable only seems to select 0 for the value_2 variable. Any help would be greatly appreciated. Thanks:
import random
keys = list(deck.keys())
def random_card_generator():
random_number = random.randint(0,8)
random_word = random.choice(keys)
if random_word.find('Ace') != -1:
choose = 0
print(random_word)
while choose != 1 or choose != 11:
choose = int(input('Would you like 1 or 11?: '))
if choose == 1 or choose == 11:
return choose, random_word
break
else:
print('That is not a valid number. Please choose either 1 or 11')
choose
elif random_word.find('King') or random_word.find('Jack') or random_word.find('Queen') != -1:
value = deck[random_word][0], random_word
return value
else:
value_1 = deck[random_word][random_number], random_word
return value_1
Upvotes: 0
Views: 59
Reputation: 1824
It's hard to be certain without seeing how your deck
is structured, but I think the error is in this line:
elif random_word.find('King') or random_word.find('Jack') or random_word.find('Queen') != -1:
This needs to be
elif random_word.find('King') != -1 or random_word.find('Jack') != -1 or random_word.find('Queen') != -1:
Upvotes: 1