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

    • ercicttech
      By ercicttech
      Hello, all..

      My AutoIT is pretty terrible - but I get by with trawling here
      I came across an issue where i had to parse a large key in a large ini file, and found that I was victim of inireadsection's limit of "Only the first 32767 chars are read for legacy reasons."
       
      I've attempted to put together some terrible code that parses an ini section.
      It's absolutely nowhere near good, but I figured I'd put it here so that folk who know what they're doing can laugh at improve it.
      $Ini = @ScriptDir & "\bigini.ini" Dim $IniArray[0][2] $KeyName = "Person" $R = FileOpen($Ini, 0) $IniStr = FileRead($R) FileClose($R) $Start = StringInStr($iniStr, "[" & $KeyName & "]") If $Start = 0 then Msgbox(16, "Error", "String not found") Exit EndIf $Stop = StringInStr($IniStr, @CRLF & "[", 0, 1, ($Start + 1)) If $Stop = 0 then $Stop = StringLen($IniStr) EndIf $String = StringMid($IniStr, $Start, ($Stop - $Start)) $Split = StringSplit($String, @CRLF, 1) $KeyCount = 0 Dim $IniArray[65535][2] For $Loop = 1 to $Split[0] $Add = "Y" $Str = $Split[$Loop] $EQBreak = StringInStr($Str, "=") Select Case StringMid($Str, 1, 1) = ";" $Add = "N" Case $EQBreak = 0 $Add = "N" Case Else $Add = "Y" EndSelect If $Add = "Y" then $KeyCount = $KeyCount + 1 $Key = StringMid($Str, 1, ($EQBreak - 1)) $Val = StringMid($Str, ($EQBreak + 1)) $IniArray[$KeyCount][0] = $Key $IniArray[$KeyCount][1] = $Val EndIf Next Redim $IniArray[$KeyCount +1][2] ; Add the number of hits to 00 to match inireadsection $IniArray[0][0] = $KeyCount _ArrayDisplay($IniArray) ; Do stuff with the Array like you would inireadsection  
    • CodeName_SexBobomb
      By CodeName_SexBobomb
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Test () Func Test() $Form1 = GUICreate("Form1", 414, 212, 1449, 1197) $Group1 = GUICtrlCreateGroup("Group1", 0, 0, 201, 161) Global $Combo1 = GUICtrlCreateCombo("", 0, 16, 201, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) $Data = GUICtrlSetData($Combo1, "Combo 1|Combo 2|Combo 3") Global $Input1 = GUICtrlCreateInput("", 0, 48, 201, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("Group2", 210, 0, 200, 160) Dim $LABELS[20] Local $DIRECTORY = @ScriptDir & "\Test.ini" Local $SECTION = IniReadSection($DIRECTORY, "Section 1") Local $RESULTS = "" For $r = 1 To $SECTION[0][0] $RESULTS &= $SECTION[$r][1] & @CRLF Next $RESULTS = StringTrimRight($RESULTS, 1) For $N = 0 To 10 $LABELS[$N] = GUICtrlCreateLabel($RESULTS, 220, 15, 200, 100) Next GUICtrlCreateGroup("", -99, -99, 1, 1) $Button1 = GUICtrlCreateButton("Save", 80, 170, 121, 33) $Button2 = GUICtrlCreateButton("Exit", 210, 170, 121, 33) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _WriteData () Case $Button2 Exit EndSwitch WEnd EndFunc _WriteData () Func _WriteData () Local $TestData = GUICtrlRead($Combo1) Local $TestInput = GUICtrlRead($Input1) Local $Directory = @ScriptDir & "\Test.ini" IniWrite ($Directory, "Section 1", "", "" & $TestData & " " & $TestInput & @CRLF & "") EndFunc Hello Friends,
        Perhaps one of you can assist me. Currently I have a semi-working script. The goal of this script is to write the values of the combo box into an INI file and read said INI files. So far it does this.. but the issue is, It writes over line 1. The goal is to write on a new line each time to create a continuous log of submitted data.
    • GordonFreeman
      By GordonFreeman
      Hi, i'm trying to save data in an ini key that contains @LF and @CRLF (to use in an edit control). But @LF and @CRLF cause error in ini files (because it breaks the line). Then im trying to find a workaround. Here's the script thanks in advance:
       
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 438, 192, 124) $hEDIT = GUICtrlCreateEdit("",11,11,600,400) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### IniWrite("JustATest.ini","TestSec","TestKey","TestValue " & @CRLF & "Testing" & @LF & "test") $sData = IniRead("JustATest.ini","TestSec","TestKey","") GUICtrlSetData($hEDIT,$sData) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
    • Eli_jahbot
      By Eli_jahbot
      My esteemed Autoits I need your help once again.
      I'm trying to figure out how to create a loop that gets 1 value from an array and repeats until each value from the array has been used. I have never used arrays before and I know once I learn more things should get easier for me. 
      Here is what Im trying to do:
      -Have an array of values that determine what application i log into. ex: app1, app2, app3, app4 etc.
      -Have a loop that repeats a process sequentially using each value in the array to finish the process for each app1, app2, app 3 and so forth. I have 30 apps that I need to update on a regular basis and getting this sorted out is what I perceive to be the best way to do it.
      Here is my feeble attempt that obviously fails:
      #include <msgboxconstants.au3>
      #include <Constants.au3>
      #include <array.au3>
      Login()
      Func Login()
          local $array[30] = ["10", "11", "12",etc etc]
          ;;Local $site = InputBox("ERx Site","What site do you want to login as?","","")
          Local $userid = InputBox("ERx Login", "What is your username?", "", "")
          Local $Passwd = InputBox("Security Check", "Enter your UAT password.", "", "*")
      for $1 = 1 to 30(I need to do the same steps in 30 different apps)
      run("Z:launch.exe")
      WinWaitActive("Input")
      Send (Sequential ARRAY VALUE HERE)
      Send("{ENTER}")
      WinWaitActive("window")
      Send($userid)
      Send("{TAB}")
      send($Passwd)
      Send("{ENTER}")
      WinWaitActive("[CLASS:SunAwtDialog]")
      Sleep(500)
      WinClose("Home Page")
      Next
      EndFunc
       
      your help is greatly appreciated.
      Thanks for your time
    • 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!