python - Picking random sub-routines from a list -
This is for Python 3.3. When I run this program, it always runs sub-routine "Fencing".
I want to make it so that it is possible to choose a random sub-routine from this list. So, it will ask a random arithmetic question.
import random idf func_addition (): a = random.randint (1,25) b = random.randint (1,25) c = a + B answer = int (input "(" What is "+ str (a) +" + "+ (str) (b) +"? ")) Func_subtraction (): d = random.randint (10,25) e = random (1.10" F + AR (D) + "-" + str (e) + "?")) DRF func_multiplication (): g = random.randint (1,10) H = random.Rendent (1,10) I = g * h answer = Intestine (int ("what" + str (g) + "x" + str (h) + "?")) My_list = [func_subtraction (), func_multiplication ()] name = input ("what is your name?" ) Print ("Hello" + str (name) + "and welcome to the arithmetic quiz") Unt (random .choice (my_list))
Remove the legs or you The list will be made when the call will be made.
my_list = [func_addition, func_subtraction, func_multiplication] name = input ("what is our name?") "Print" ("hello {} and welcome to the arithmetic quiz". Format (name)) chc = random.choice (my_list) # random function chc () # call function
You have not seen your variable to use, I confirm the answer For something like the following:
def func_addition (): a = random.randint (1,25) b = random (1,25) C = A + B answer = int (input ("what is {} + {}?". Format (A, B))) Answer == c: print ("Well done, that's right ") And: Print (" Sorry, that's wrong, right answer is {} ". Format (C))
Comments
Post a Comment