[英]The random.randint import doesn't seem to be working correctly
This is my first question on Stack and I am really hoping someone else has had this same problem and can help me.这是我在 Stack 上的第一个问题,我真的希望其他人也遇到过同样的问题并且可以帮助我。
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.我使用 Python 3.7.6 编写了以下代码,该代码根据我建立的字典随机选择卡片套装和相应的值。 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.这段代码在昨天和前一天工作得非常好,但是,今天 random_number 变量似乎只适用于 value_2 变量的 select 0。 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
It's hard to be certain without seeing how your deck
is structured, but I think the error is in this line:如果不看你的deck
组的结构很难确定,但我认为错误就在这一行:
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:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.