Jump to content
Sign in to follow this  
hackersarchangel

making a question and answer generator

Recommended Posts

hackersarchangel

Ok so here's my "evil plan" lol: I am working on making a test to help me study for the A+. The idea is that I want to make it modular so I can specify a battery of tests.

My bright idea was to make an ini file generator, since that has built functions and a method for sorting. The generator is mostly done, it's a basic one to make multiple choice questions. Here's the tricky bit: I want to be able to mark each answer with 1, 2, 3, and 4 so I can then have the test program grab the answers at random, but still relevant to each question, and not show the numbers so it's harder to tell which ones are which.

Example:

Q. Who founded Apple Computer, Inc?

1) Steve Ballmer

2)Steve Jobs and Steve Wozniak

3) Bill Gates and Steve Jobs

4) Tom Petty and the Heartbreakers

but have that be in a different order everytime I take the test, so I can't cheat even though I'm writing the test lol. I have that figured out as far as how it's organized with the questions, just need to figure out how to grab the questions and answers, but do it in a way that it's not seen in the test, so I can randomize them. So far I'm sure I can randomize the question order, but still not sure on how to keep it from repeating a question.

Here's my code so far for the ini generator, the Test portion I'll be working on as soon as I can think of a way to have it pick a question at random. Partially why I'm here :)

#include <GUIConstantsEx.au3> ;Constants for GUI Events
#include <WindowsConstants.au3>

Global $Answer, $Answer_input[4], $counter = 0, $Build_bttn, $Question, $Question_input


_Create_GUI()
Func _Create_GUI()

    ;To implement a reset function, make everything in the GUI first, THEN put all the case stuff inside
    ;_Main().
    HotKeySet("{F3}","_Main") ;A program reset switch, in case a function gets funky and doesn't process right.
    GUICreate("Question and Answer Generator Version 0.1",640,480)

    ;The code for adding questions and answers to the .ini file.
    $Question_input = GUICtrlCreateEdit("Question goes here",45,45, 250, 75)
    $Answer_input[0] = GUICtrlCreateInput("1)", 45, 150, 300, 20)
    $Answer_input[1] = GUICtrlCreateInput("2)", 45, 175, 300, 20)
    $Answer_input[2] = GUICtrlCreateInput("3)", 45, 200, 300, 20)
    $Answer_input[3] = GUICtrlCreateInput("4)", 45, 225, 300, 20)


    $Build_bttn = GUICtrlCreateButton("Add to File", 525,440)

_Main()
EndFunc
Func _Main()


    GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $Gui_Event_Close
            Exit
        Case $Build_bttn
        $Question = GUICtrlRead($Question_input)
        $Answer = GUICtrlRead($Answer_input[0]) & @LF & GUICtrlRead($Answer_input[1]) & @LF & GUICtrlRead($Answer_input[2]) & @LF & GUICtrlRead($Answer_input[3])
        If ($counter) < 10 Then
            $counter = $counter+1
            IniWrite("AlphaTest.ini","Questions","Question_" & $counter, $Question)
            IniWriteSection("AlphaTest.ini","Answer_" & $counter,$Answer)
        EndIf
EndSwitch
WEnd
EndFunc

I understand this is a complicated project, one I'm willing to share back with the community of course since the idea is to make it a simple generator and then just point the Test exe to the q&a file

Edited by hackersarchangel

Share this post


Link to post
Share on other sites
czardas

You could put you questions and answers into separate arrays and shuffle them. Here's a very simple method to shuffle an array I wrote the other day. You can find other methods

Func _ArrayRandomShuffle(ByRef $aArray)
    Local $iRandom, $iBound = UBound($aArray) -1
    For $i = 0 To $iBound
        $iRandom = Random(0, $iBound, 1)
        If $i <> $iRandom Then _ArraySwap($aArray[$i], $aArray[$iRandom])
    Next
EndFunc

Actually I realise this function is the same as that posted by jchd in the thread linked to above.

Edited by czardas

Share this post


Link to post
Share on other sites
hackersarchangel

Ingenius! Grab the section of answers, and shuffle them. I could make a section for the questions, using an identifying system to mark the questions and answer sets together and then pair them up by looking up that answer set then shuffling the answer set afterwards.

Share this post


Link to post
Share on other sites
czardas

It's quite simple really. You could include the real answer, a trick question type answer (misleading), along with some randomly selected answers. Then do what you said.

Edited by czardas

Share this post


Link to post
Share on other sites
sleepydvdr

Just for the fun of it, I wrote a version of your script. Maybe it will give you a different perspective. For my scirpt, I used just numbers for the section names and values in the .ini file. I think that will make it easier to work with randomly picking questions and answers.

I will try to work on a console for asking you questions. This one is just for adding questions to the ini file.

#include <GUIConstants.au3>

$iniFile = @ScriptDir & "AlphaTest.ini"
$Form1_1 = GUICreate("Form1", 679, 365)
$Edit1 = GUICtrlCreateEdit("", 32, 32, 537, 105)
$Label1 = GUICtrlCreateLabel("Enter your question:", 32, 8, 98, 17)
$Label2 = GUICtrlCreateLabel("Answer pool:", 32, 168, 65, 17)
$Input1 = GUICtrlCreateInput("", 32, 192, 537, 21)
$Input2 = GUICtrlCreateInput("", 32, 224, 537, 21)
$Input3 = GUICtrlCreateInput("", 32, 256, 537, 21)
$Input4 = GUICtrlCreateInput("", 32, 288, 537, 21)
$Button1 = GUICtrlCreateButton("Save Question", 272, 328, 115, 25)
$Label3 = GUICtrlCreateLabel("Correct Answer", 584, 160, 76, 17)
$Radio1 = GUICtrlCreateRadio("", 584, 192, 113, 17)
$Radio2 = GUICtrlCreateRadio("", 584, 224, 113, 17)
$Radio3 = GUICtrlCreateRadio("", 584, 256, 113, 17)
$Radio4 = GUICtrlCreateRadio("", 584, 288, 113, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _WriteToIni()
    EndSwitch
WEnd

Func _WriteToIni()
    Local $error = 0
    
    $question = GUICtrlRead($Edit1)
    $ans1 = GUICtrlRead($Input1)
    $ans2 = GUICtrlRead($Input2)
    $ans3 = GUICtrlRead($Input3)
    $ans4 = GUICtrlRead($Input4)
    $readradio1 = GUICtrlRead($Radio1)
    $readradio2 = GUICtrlRead($Radio2)
    $readradio3 = GUICtrlRead($Radio3)
    $readradio4 = GUICtrlRead($Radio4)
    
    If $readradio1 = 1 Then
        $correctAns = $ans1
    ElseIf $readradio2 = 1 Then
        $correctAns = $ans2
    ElseIf $readradio3 = 1 Then
        $correctAns = $ans3
    ElseIf $readradio4 = 1 Then
        $correctAns = $ans4
    Else
        MsgBox(0, "Error", "Please select which answer is correct")
        $error = 1
    EndIf
    
    If $error <> 1 Then
        $sectionNames = IniReadSectionNames($iniFile)
        $nextQuestion = UBound($sectionNames) - 1
        If $nextQuestion < 1 Then
            $nextQuestion = 0
        EndIf
        IniWrite($iniFile, $nextQuestion, "Question", $question)
        IniWrite($iniFile, $nextQuestion, "1", $ans1)
        IniWrite($iniFile, $nextQuestion, "2", $ans2)
        IniWrite($iniFile, $nextQuestion, "3", $ans3)
        IniWrite($iniFile, $nextQuestion, "4", $ans4)
        IniWrite($iniFile, $nextQuestion, "Correct", $correctAns)
    EndIf
EndFunc
Edited by sleepydvdr

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites
hackersarchangel

Wow lol didn't think this would be such a popular concept :)

I'll test the script in a bit, at work and a little busy lol

Share this post


Link to post
Share on other sites
sleepydvdr

I modified the previous script, so be sure to use the newer version. Here's the console to be asked the questions:

#include <GUIConstants.au3>
#include <Array.au3>

Dim $aArray[4]
$iniFile = @ScriptDir & "AlphaTest.ini"
Global $question, $correctAns, $error = 0

_GetQuestion()

$Form1 = GUICreate("Study Helper", 633, 341, 193, 125)
$Label1 = GUICtrlCreateLabel($question, 32, 48, 572, 73)
$Label2 = GUICtrlCreateLabel("Question:", 24, 16, 49, 17)
$Radio1 = GUICtrlCreateRadio($aArray[0], 40, 168, 545, 17)
$Radio2 = GUICtrlCreateRadio($aArray[1], 40, 192, 545, 17)
$Radio3 = GUICtrlCreateRadio($aArray[2], 40, 216, 545, 17)
$Radio4 = GUICtrlCreateRadio($aArray[3], 40, 240, 545, 17)
$Button1 = GUICtrlCreateButton("Submit", 264, 288, 75, 25, 0)
GUISetState(@SW_SHOW)



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _CheckAnswer()
            $error = 0
    EndSwitch
WEnd

Func _GetQuestion()
    $namesOfSections = IniReadSectionNames($iniFile)
    $numberOfQuestions = $namesOfSections[0]
    $randomNumber = Random(0, $numberOfQuestions - 1, 1)
    $question = IniRead($iniFile, $randomNumber, "Question", "")
    $aArray[0] = IniRead($iniFile, $randomNumber, "1", "")
    $aArray[1] = IniRead($iniFile, $randomNumber, "2", "")
    $aArray[2] = IniRead($iniFile, $randomNumber, "3", "")
    $aArray[3] = IniRead($iniFile, $randomNumber, "4", "")
    $correctAns = IniRead($iniFile, $randomNumber, "Correct", "")
    Local $iRandom, $iBound = UBound($aArray) -1
    For $i = 0 To $iBound
        $iRandom = Random(0, $iBound, 1)
        If $i <> $iRandom Then _ArraySwap($aArray[$i], $aArray[$iRandom])
    Next
EndFunc

Func _CheckAnswer()
    If GUICtrlRead($Radio1) = 1 Then
        $answer = $aArray[0]
    ElseIf GUICtrlRead($Radio2) = 1 Then
        $answer = $aArray[1]
    ElseIf GUICtrlRead($Radio3) = 1 Then
        $answer = $aArray[2]
    ElseIf GUICtrlRead($Radio4) = 1 Then
        $answer = $aArray[3]
    Else
        MsgBox(0, "Error", "You did not select anything")
        $error = 1
    EndIf
    
    If $error <> 1 Then
        If $answer = $correctAns Then
            MsgBox(0, "Correct", "You got the question correct!")
        Else
            MsgBox(0, "Incorrect", "Sorry, wrong answer. The correct answer is:" & @CRLF & @CRLF & $correctAns)
        EndIf
    EndIf
    
    _ResetQuestion()
EndFunc

Func _ResetQuestion()
_GetQuestion()    
GUICtrlSetData($Label1, $question)
GUICtrlSetData($Radio1, $aArray[0])
GUICtrlSetData($Radio2, $aArray[1])
GUICtrlSetData($Radio3, $aArray[2])
GUICtrlSetData($Radio4, $aArray[3])
EndFunc

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites
sleepydvdr

The first script I posted creates the ini file. This is what I used for testing purposes:

[0]
Question=How many days are in a week?
1=4
2=8
3=7
4=3
Correct=7
[1]
Question=What color is the sky?
1=Blue
2=Red
3=Green
4=Purple
Correct=Blue
[2]
Question=How old are you?
1=24
2=99
3=88
4=6
Correct=24

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • AnonymousX
      By AnonymousX
      Hello,
      So this may be more of a challenge of effective programming then specific to AutoIT but I want to solve this problem with AutoIT  so i'm putting it here. (If someone has a better language to solve with I'm all ears)
       
      So the task I'm trying to achieve is that I have multiple .CSV files that have: year, month, day, hour, value. I need to be able to sum up all the values that have the same date/time, then find which date and time has the maximum value.
       
      The problem is that each file may or may not have same amount of days/hours as the rest. So I need to devise a way to handle this. 
       
      Example:
      File A   File B   File C 2018 1 1  1:00 10   2018 1 1 2:00 10   2018 1 1  1:00 10 2018 1 1  2:00 12   2018 1 1 3:00 12   2018 1 2 1:00 12 2018 1 1  3:00 14   2018 1 1 4:00 14   2018 2 1  1:00 16 2018 2 1  1:00 16   2018 2 1  1:00 16              
       Answer I want to be spit out is Feb 1st 2018 at 2:00 with value of 48
       
      So far I've got code to store all .CSV files to an array, then a loop to go through each csv, but not sure how to effectively manipulate the data. Keep in mind each file has over 7000 time entry points.
       
      If anyone can solve this that would be pretty awesome! 
      #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> RefineData() Func RefineData() Local $i, $filenum, $file, $csvArray, $FilePath = @ScriptDir $fileList = _FileListToArrayRec($FilePath, "*.csv", 1) ;Create and array of all .csv files within folder Local $chkArray[UBound($fileList)][2] ;=====Loop through the .csv files within the folder====== For $filenum = 1 To UBound($fileList) - 1 Step 1 $file = $fileList[$filenum] $sFilePath = $FilePath & "\" & $file ;=====Create array based on csv file===== _FileReadToArray($sFilePath, $csvArray, $FRTA_NOCOUNT, ",") ;#### Operations here ###### next msgbox(0,"", "Date: " & $date_of_max & "Value: " & $maxVal );display solution endfunc  
    • corz
      By corz
      Associative Array Functions
      I've seen a couple of UDFs for this on the forum. One of them I quite like. But it's still nearly not as good as this method, IMHO.
      I don't recall if I discovered the "Scripting.Dictionary" COM object myself or if I got the original base code from somewhere online. I have recently searched the web (and here) hard for any AutoIt references to this, other than my own over the years I've been using this (in ffe, etc..), and I can find nothing, so I dunno. If anyone does, I'd love to give credit where it's due; this is some cute stuff! It could actually be all my own work! lol
      At any rate, it's too useful to not have posted somewhere at autoitscript.com, so I've put together a wee demo.
      For those who haven't heard of the COM "Scripting.Dictionary".. 
      If you've ever coded in Perl or PHP (and many other languages), you know how useful associative arrays are. Basically, rather than having to iterate through an array to discover it's values, with an associative array you simply pluck values out by their key "names".
      I've added a few functions over the years, tweaked and tuned, and this now represent pretty much everything you need to easily work with associative arrays in AutoIt. En-joy!
      The main selling point of this approach is its simplicity and weight. I mean, look at how much code it takes to work with associative arrays! The demo is bigger than all the functions put together! The other selling point is that we are using Windows' built-in COM object functions which are at least theoretically, fast and robust.
      I've used it many times without issues, anyhow, here goes..
      ; Associative arrays in AutoIt? Hells yeah! ; Initialize your array ... global $oMyError = ObjEvent("AutoIt.Error", "AAError") ; Initialize a COM error handler ; first example, simple. global $simple AAInit($simple) AAAdd($simple, "John", "Baptist") AAAdd($simple, "Mary", "Lady Of The Night") AAAdd($simple, "Trump", "Silly Man-Child") AAList($simple) debug("It is said that Trump is a " & AAGetItem($simple, "Trump") & ".", @ScriptLineNumber);debug debug("") ; slightly more interesting.. $ini_path = "AA_Test.ini" ; Put this prefs section in your ini file.. ; [test] ; foo=foo value ; foo2=foo2 value ; bar=bar value ; bar2=bar2 value global $associative_array AAInit($associative_array) ; We are going to convert this 2D array into a cute associative array where we ; can access the values by simply using their respective key names.. $test_array = IniReadSection($ini_path, "test") for $z = 1 to 2 ; do it twice, to show that the items are *really* there! for $i = 1 to $test_array[0][0] $key_name = $test_array[$i][0] debug("Adding '" & $key_name & "'..");debug ; key already exists in "$associative_array", use the pre-determined value.. if AAExists($associative_array, $key_name) then $this_value = AAGetItem($associative_array, $key_name) debug("key_name ALREADY EXISTS! : =>" & $key_name & "<=" , @ScriptLineNumber);debug else $this_value = $test_array[$i][1] ; store left=right value pair in AA if $this_value then AAAdd($associative_array, $key_name, $this_value) endif endif next next debug(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" , @ScriptLineNumber);debug AAList($associative_array) debug(@CRLF & "Removing 'foo'..");debug AARemove($associative_array, "foo") debug(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" , @ScriptLineNumber);debug AAList($associative_array) debug(@CRLF & "Removing 'bar'..");debug AARemove($associative_array, "bar") debug(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" , @ScriptLineNumber);debug AAList($associative_array) quit() func quit() AAWipe($associative_array) AAWipe($simple) endfunc ;; Begin AA Functions func AAInit(ByRef $dict_obj) $dict_obj = ObjCreate("Scripting.Dictionary") endfunc ; Adds a key and item pair to a Dictionary object.. func AAAdd(ByRef $dict_obj, $key, $val) $dict_obj.Add($key, $val) If @error Then return SetError(1, 1, -1) endfunc ; Removes a key and item pair from a Dictionary object.. func AARemove(ByRef $dict_obj, $key) $dict_obj.Remove($key) If @error Then return SetError(1, 1, -1) endfunc ; Returns true if a specified key exists in the associative array, false if not.. func AAExists(ByRef $dict_obj, $key) return $dict_obj.Exists($key) endfunc ; Returns a value for a specified key name in the associative array.. func AAGetItem(ByRef $dict_obj, $key) return $dict_obj.Item($key) endfunc ; Returns the total number of keys in the array.. func AACount(ByRef $dict_obj) return $dict_obj.Count endfunc ; List all the "Key" > "Item" pairs in the array.. func AAList(ByRef $dict_obj) debug("AAList: =>", @ScriptLineNumber);debug local $k = $dict_obj.Keys ; Get the keys ; local $a = $dict_obj.Items ; Get the items for $i = 0 to AACount($dict_obj) -1 ; Iterate the array debug($k[$i] & " ==> " & AAGetItem($dict_obj, $k[$i])) next endfunc ; Wipe the array, obviously. func AAWipe(ByRef $dict_obj) $dict_obj.RemoveAll() endfunc ; Oh oh! func AAError() Local $err = $oMyError.number If $err = 0 Then $err = -1 SetError($err) ; to check for after this function returns endfunc ;; End AA Functions. ; debug() (trimmed-down version) ; ; provides quick debug report in your console.. func debug($d_string, $ln=false) local $pre ; For Jump-to-Line in Notepad++ if $ln then $pre = "(" & $ln & ") " & @Tab ConsoleWrite($pre & $d_string & @CRLF) endfunc  
      ;o) Cor
    • Jibsbrown
      By Jibsbrown
      Hope someone can find what I've done wrong, because I have no idea. I'm sure its very simple fix.
      Currently after selecting the folder for files the Listview the path is recorded in the INI file this which works. After submitting the ListView changes with the loop the INI file is over written and the file section name is not being written.
      Any idea or examples for the solution? Forma searches and help file have not provided the answer(s). Or I'm just not seeing my mistake, which I'm sure is the real problem.
      #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; *** Start added by AutoIt3Wrapper *** #include <FileConstants.au3> #include <MsgBoxConstants.au3> ; *** End added by AutoIt3Wrapper *** #include <Array.au3> #include <File.au3> #include <FileConstants.au3> #include <ListViewConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GUIListViewEx.au3> ;User choses folder path Global $Path = FileSelectFolder("Select Upadates Folder", @ScriptDir) $upsPath = $Path ;MsgBox(0, "", $Path, 5) $fUpsList = "InstallList.ini" FileOpen($fUpsList) IniWriteSection($fUpsList, "Path", $Path) FileClose($fUpsList) Global $aUpdates = _FileListToArrayRec($Path, "*.*", $FLTAR_FILES) ; All files in folder loaded into array for LV $sFileCount = $aUpdates[0] ; Use file count for error checking - not added yet 3/29 ConsoleWrite($sFileCount & @CRLF) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 482, -1, -1) $Group1 = GUICtrlCreateGroup("Group1", 40, 24, 400, 377) $List1 = GUICtrlCreateListView("Update Files", 48, 72, 385, 305) _GUICtrlListView_SetColumnWidth($List1, 0, 385) $Submit = GUICtrlCreateButton("Submit", 400, 424, 75, 25) $Exit = GUICtrlCreateButton("Exit", 504, 424, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### For $i = 1 To UBound($aUpdates) - 1 GUICtrlCreateListViewItem($aUpdates[$i], $List1) Next GUISetState() $lUps = _GUIListViewEx_Init($List1, $aUpdates, 0, 0, True) _GUIListViewEx_MsgRegister() While 1 $vRet = _GUIListViewEx_EventMonitor() ; Reread GLVEx Help doc If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error) EndIf Switch @extended Case 0 Case 4 EndSwitch $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Submit $aContent = _GUIListViewEx_ReturnArray($lUps) _FileWriteFromArray($fUpsList, $aContent) ;this $error check returns 5 - Start index is greater than the $iUbound parameter ;So if the list is empty, it returns error 5 If @error = 5 Then FileOpen($fUpsList) IniWriteSection($fUpsList, "InstallOrder", "") FileClose($fUpsList) EndIf Exit Case $Exit Exit EndSwitch WEnd  
    • kartune
      By kartune
      Hi, i would like to know if there is a possible way to use subsections for ini files?
      For example, my ini file would look something like this:
       
      Clientname.ini
      [Info]
      Country=USA
      Type=Distributor
       
      [Costs]
      [[JAN]] <----- subsection
      cost1=----
      cost2=----
      [[FEB]]
      cost1=----
      cost2=----
       
      [Sales]
      [[JAN]] <----- subsection
      sale1=----
      sale2=----
      [[FEB]]
      sale1=----
      sale2=----
       
      [Profits]
      [[JAN]] <----- subsection
      prof1=----
      prof2=----
      [[FEB]]
      prof1=----
      prof2=----
       
      The sales would be inputed everyday by the script, and then whenever viewed, i would be using an array to view every sale/cost/profit under the subsection
       
       
      Thanks for your time!
    • TheWizEd
      By TheWizEd
      How do I work with 2D arrays.  I've tried this but get errors.
      Local $aTest[4][4] = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
      ;$aTest[0][] = [10,11,12]  ; Error at []
      Local $sTest = ""
      For $i = 0 To UBound($aTest)-1
        Local $aExtract = _ArrayExtract($aTest,$i,$i)
        $sTest = $sTest & MyTest($aExtract)
      Next
      Func MyTest($aTemp)
        _ArrayDisplay($aTemp)
        ; Error at    v $aTemp
        Return String($aTemp[0]) & " - " & String($aTemp[1]) & " - " & String($aTemp[2]) & @CRLF
      EndFunc
       
       
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.