我的程序目前看起来像这样:
import random
answer = ""
correct_math = ["2", "3", "1"]
math_problems = ["What is the square root of 25? 1.) 4 2.) 5 3.) 6: ", "What is 97 + 113? 1.) 200 2.) 100 3.) 210: ", "What is 954 - 164? 1.) 790 2.) 835 3.) 756: "]
answer = input("STUDY GUIDE: What subject are you trying to study? Math (1) Science (2) History (3) : ")
if answer == "1":
answer = input(random.choice(math_problems))我正在尝试让它调用一个随机问题来学习,但我不知道如何让它调用的随机问题等于答案列表中的答案。我将它们设置为1:1,这样问题列表中的第一项就会在correctmath列表中按顺序回答。我只需要知道如何判断随机抽取的问题的正确答案是否有意义。而且,我的代码没有像这样的间隔,它只是不允许我添加新的段落。
发布于 2021-04-22 07:35:13
下面是如何对两个numpy数组进行随机排序,并保持它们同时排序的方法:
import numpy as np
data = np.array(["a","b","c","d"])
labels = np.array([1,2,3,4])
# create a numbered list of your indexes and shuffle it
ind = list(range(len(data)))
np.random.shuffle(ind)
data_rand = data[ind]
labels_rand = labels[ind]我也做了一个快速的Stackoverflow搜索,这里还有一些其他的方法:Better way to shuffle two numpy arrays in unison
https://stackoverflow.com/questions/67204641
复制相似问题