gpt4 book ai didi

python - 尝试获取可以根据输出进行检查的随机代码

转载 作者:行者123 更新时间:2023-12-01 06:26:02 24 4
gpt4 key购买 nike

尝试使用 while 循环来要求用户输入打乱后的代码

  • 如果为 true,则 login_success() 运行

  • 否则 twofactor() 运行

但是,我无法将输入与打乱的代码相匹配,这与它是一个列表有关吗?我尝试过 .map.join 但没有运气。

def twofactor():

global RandomCode
RandomCode = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
flag = True

while flag:
random.shuffle(RandomCode)
print(str(RandomCode[0:6]))
entercode = str(input("Enter the code: "))
if entercode != RandomCode:

print("Incorrect code! ")
print("A new code will generate below: ")
twofactor()
else:
flag = FALSE
print ("Success !")
login_success()

最佳答案

import random
def login_success () :
pass

def twofactor():

global RandomCode
RandomCode = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

flag = True

while flag:
random.shuffle(RandomCode)
# --- Here's what you needed ---
RandomCodeString = ''.join (str (num) for num in RandomCode[0:6])
print(RandomCodeString)
entercode = str(input("Enter the code: "))
if entercode != RandomCodeString:

print("Incorrect code! ")
print("A new code will generate below: ")
twofactor()
else:
flag = False
print ("Success !")
login_success()

twofactor ()

关于python - 尝试获取可以根据输出进行检查的随机代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60138474/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com