Quizbank/Python/numerical/mock.1.py

From Wikiversity
Jump to navigation Jump to search
#Creates one quiz question with random (numerical) parameters
#First we import some modules that we will need:
import os, csv, re, time, shutil, random, sys, math
from numericalFunctions import roundSigFig, express, QuesVar, makeAnswers
random.seed() #needed to make random numbers more "random"
_R1=True #Do not use this "magic" variable  programming style?
### REQUIRED HEADER=hidden statement that begins each question !!!!!!!
questionHeader= 'Attribution Public Domain CC0:'#Attribution
### RENDITION (typically 20 or so:)
questionRenditions=3 
#These statements require no editing or modification:
questionQuestion=''#initial value
questionRenditionCount=0#initial value
questionName = os.path.basename(__file__)[:-3]
answerList=[]
questionList=[]
print(questionName+'\n' + questionHeader+'\n')
questionFile=open(questionName+'.txt','w')
questionFile.write('_name_'+questionName)
questionFile.write('\n_head_'+questionHeader+'\n')
'''If copying an example from OpenStax I paste it here'''
for questionRenditionCount in range(1,1+questionRenditions):   
###*EDIT: Declare variables (first,low,high,_R1):*****edit below*##########
    apples1=   QuesVar(2, 3, 9, _R1)#
    apples2=   QuesVar(2, 3, 9, _R1)#
### NO EDIT BELOW (write question begins)
    print('Rendition '+str(questionRenditionCount)+': ')
    questionFile.write('_R_'+str(questionRenditionCount)+'\n')
###### Add text from book and write question: (xx.t )     ##########
    questionQuestion=\
    "[[File:Der Apfel ist im LKW.svg|thumb|120px]]"\
    "Recall that the units of apples is <math>\\mathcal{A}</math>. "\
    "How many apples are "+apples1.t+"&nbsp;<math>\\mathcal{A}</math> "\
    "plus "+apples2.t+"&nbsp;<math>\\mathcal{A}</math>?"
### NO EDIT HERE ##################################
    print(questionQuestion)
    questionFile.write('_Q_'+questionQuestion+'\n')
###*EDIT BELOW**(solve using xx.v **********EditEditEdit
    mu0=math.pi*4e-7
    a1=apples1.v #sometimes its convenient to rename the objects
    a2=apples2.v
    atotal=a1+a2
    ###############################################
    questionAnswer= atotal  #questionAnswer is magic !!!!!!!!!!
    ### Adjust as needed (expecially UNITS) 
    answerFactor=1.15 #Scales how far the wrong answers are apart
    answerPre=''
    answerPost='&nbsp;<math>\\mathcal{A}</math>' #DON'T FORGET THIS!!!!
### Usually STOP HERE ###############################
    print('Answer: '+'{0:1.5E}'.format(questionAnswer), 
     ':' + answerPre+ '#' + answerPost)
    answerString=makeAnswers(answerPre,
                         questionAnswer,answerPost, answerFactor)
    print(answerString)
    questionFile.write(answerString)
    _R1=False #Loops back with randoms
questionFile.close() #This text file will be later called to create quiz