0

My program currently looks like this:

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))

I'm trying to make it so it calls a random question to study but I don't know how to make it so that the question randomly that it calls will equal the answer in the answer list. I have them set up 1:1 so the first item in the problem list is answered in the correctmath list in order. I just need to know how to call the correct answer pertained to the question randomly pulled if that makes sense. Also my code isn't spaced out like that it just wouldn't let me add new paragraphs.

Vickel
  • 7,879
  • 6
  • 35
  • 56

1 Answers1

0

Here is how you can randomly sort two numpy arrays and keep them simultaneously ordered:

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]

I also did a quick Stackoverflow search, here are some other ways also: Better way to shuffle two numpy arrays in unison

rocket_boomerang_19
  • 519
  • 1
  • 3
  • 19