Sign in to follow this  
Followers 0
hackersarchangel

making a question and answer generator

10 posts in this topic

#1 ·  Posted (edited)

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



#2 ·  Posted (edited)

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

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

#4 ·  Posted (edited)

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

#5 ·  Posted (edited)

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

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

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

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

Ah sorry I didn't try the first script. I like the example you made. It's looking very promising. :)

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  
Followers 0

  • Similar Content

    • RC86
      By RC86
      Afternoon, I could very well be doing this wrong so feel free to totally advise otherwise - I'm wanting to use a GUI to first display a key from within an INI file, then secondly change the INI file by using a FileSelectFolder command but then I want to see the GUI change to reflect the change I've just made.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) $Input1 = GUICtrlCreateInput(Iniread(@WorkingDir & "\test.ini","Path","FilePath",""), 64, 80, 121, 21) $Button1 = GUICtrlCreateButton("Change", 200, 80, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $selectedFolder = FileSelectFolder("Select Log Path Directory",@WorkingDir,0) If NOT $selectedFolder = "" Then $newLogPath = IniWrite(@WorkingDir & "\test.ini","Path","FilePath",$selectedFolder) EndIf EndSwitch WEnd So 2 part question really: (1) Should I be using GUICtrlCreateInput to display my INI read from within the GUI? (2) How can I refresh the GUI to update that to read the new information I've just written to the GUI?
      Thanks!

    • 9252Survive
      By 9252Survive
      Hi All, 
       
      I am fairly new to AutoIT and I am still trying to learn, I have been using _FileListToArray to list all the files with a particular extension in an array and then loop through it for operation  (   For $i = 1 To UBound($FileArray) - 1).
      So far this has been working fine. But I am not able to figure out a problem that I have; what if I have 50 files but I only want to loop through first 10 files and then next ten and so on?  Or rather I should say, how I can I only feed max 10 files to the array at a time when I do _FileListToArray regardless of the total number of files in the folder?
      Any insight/help will be much appreciated 
    • LWC
      By LWC
      I've made a program that relies on IniReadSectionNames. It reads (~3K) Autorun.inf files in the working folder and creates a GUI based on their contents.
      I made sure to revert to a default GUI upon @error.
      But someone (with Windows XP SP3 32-bit) reported to me he always gets the default menu.
      I sent him a FileRead command instead and it works! So seemingly there's no access problem to AutoRun.inf.
      In the following demo code, I always hit success, but he always ends up with semi-success:
      Local $hIniLocation = "Autorun.inf" Local $aSections = IniReadSectionNames($hIniLocation) If @error Then $aSections = FileRead($hIniLocation) if @error then msgbox(48, "Double error", "Alternative access failed too due to:" & @crlf & @error & @crlf & @extended) else msgbox(0, "Semi-success", "IniReadSectionNames failed, but alternativaly this file contains:" & @crlf & @crlf & $aSections) endif else msgbox(0, "Success", "IniReadSectionNames worked!") endif Why is that? Is there something further to check with him?
      Autorun.inf
    • NiftRex
      By NiftRex
      I'm trying to get an array from a website so that I can just get the url, but I am not sure how. I read a bit of arrays but I have a feeling I'd have to be writing a lot more than what I should be. I will include the script I have so far and the API url for what I want.
       
      API: https://api.fast.com/netflix/speedtest?https=true&token=YXNkZmFzZGxmbnNkYWZoYXNkZmhrYWxm&urlCount=1 (I want the 'url' array that contains the url)
       
      Code:
      #include <MsgBoxConstants.au3> #include <Inet.au3> #include <Array.au3> $site = _INetGetSource('http://api.fast.com/netflix/speedtest?https=true&token=YXNkZmFzZGxmbnNkYWZoYXNkZmhrYWxm&urlCount=1') MsgBox($MB_SYSTEMMODAL, "Title", $site[1])  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning community!
      I was working on a script which read the content of a .ini file to retrieve the file that has to open, and, based on the value of a second key stored in the .ini file, set the window on top, minimized or maximized...
      I did something like this, but seems to not work properly...
      Could anyone please tell me what I'm doing wrong?
      Thank you  
       
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_x64=prova.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> ;#include <WinAPIEx.au3> #include <Array.au3> Local $sFileConfigurazione = @ScriptDir & "\configurazione_exe.ini" If(FileExists($sFileConfigurazione)) Then Local $aSezioneIni = IniReadSection($sFileConfigurazione, "CONFIGURAZIONE_EXE") If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'apertura del file: " & @CRLF & $sFileConfigurazione & @CRLF & "Errore: " & @error) Else ; Lancio dell'applicativo indicato nel file di configurazione Local $iPID = ShellExecute($aSezioneIni[1][1]) Local $hWnd If($iPID <> 0) Then Local $aWinList = WinList() For $i = 1 To $aWinList[0][0] If(WinGetProcess($aWinList[$i][1] = $iPID)) Then $hWnd = $aWinList[$i][1] EndIf Next Switch($aSezioneIni[2][1]) Case $aSezioneIni[2][1] = "MIN" ToolTip("MIN", 0, 0) WinSetState($hWnd, WinGetTitle($hWnd), @SW_MINIMIZE) Case $aSezioneIni[2][1] = "MAX" ToolTip("MAX", 0, 0) WinSetState($hWnd, WinGetTitle($hWnd), @SW_MAXIMIZE) Case $aSezioneIni[2][1] = "TOP" ToolTip("TOP", 0, 0) WinSetOnTop($hWnd, WinGetTitle($hWnd), $WINDOWS_ONTOP) EndSwitch EndIf EndIf EndIf And the .ini file is like this:
       
      [CONFIGURAZIONE_EXE] PercorsoExe=Here goes the path and the .exe to execute ModalitaAperturaExe=Here goes one of the value below /* TOP Shows the windows on top */ /* MIN Shows the window minimized */ /* MAX Shows the window maximized */