Re: looping
- To: mathgroup at smc.vnet.net
- Subject: [mg106780] Re: [mg106704] looping
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Sat, 23 Jan 2010 07:33:38 -0500 (EST)
- References: <201001210955.EAA16523@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
This is awkward too, but have a look: initialize[] := ( names = {"apple", "bob", "cat", "dog", "ear", "frog", "greg", "hippo", "i9", "joe"}; Clear[called, score, percent]; called[_] = 0; score[_] = 0; percent[any_] := Quiet@AccountingForm[100. score[any]/called[any], 3]; ) initialize[] repeat = True; While[repeat, n = RandomInteger[{1, Length@names}]; name = names[[n]]; called[name]++; Input["Was the answer correct?", SetterBar[Dynamic[result], {1 -> "correct", 0 -> "incorrect"}]]; score[name] += result; Input["Continue?", SetterBar[Dynamic[repeat], {True -> "Go on", False -> "Stop"}]] ] Grid[ Table[Through[{Identity, called, score, percent}@name], {name, names}] /. Indeterminate -> "No scores"] Bobby On Thu, 21 Jan 2010 03:55:25 -0600, glenn kuhaneck <mcguyver128 at yahoo.com> wrote: > this code is supposed to randomly select a student from a list, keep > track of how many times he/she has been called, and how many answers > they have gotten correct. > > I am having problems getting the following code to repeat on request: i > have tried do loops, while loops, and labels none have worked. please > help > > These are the sample lists I am using for the code below > name = ( { > {"apple"}, > {"bob"}, > {"cat"}, > {"dog"}, > {"ear"}, > {"frog"}, > {"greg"}, > {"hippo"}, > {"i9"}, > {"joe"} > }); score = ({ > {0}, > {0}, > {0}, > {0}, > {0}, > {0}, > {0}, > {0}, > {0}, > {0} > }); called = ({ > {0}, > {0}, > {0}, > {0}, > {0}, > {0}, > {0}, > {0}, > {0}, > {0} > }); prcnt = ( { > {0}, > {0}, > {0}, > {0}, > {0}, > {0}, > {0}, > {0}, > {0}, > {0} > } ); > > > > > this is the code to manipulate the lists created above > repeat = "yes"; > c = "wrong"; > l = Length[name]; > n = RandomInteger[l - 1] + 1; > > > Label[begin] > "Student #" > n > name[[n]] > called[[n]] += 1; > "# times called" > called > "Old Score" > score > Input["Was the answer correct?", Button["Yes", c = "Right"]]; > If[c == "Right", score[[n]] += 1]; c > "New Score" > score > "Your # of Correct Answers" > score[[n]] > "Your %" > prcnt[[n]] = score[[n]]/called[[n]] > "Class %" > prcnt > Input["Another ?", Button["No", repeat = "no"]]; > If[repeat == "yes", Goto[begin], Goto[end]]; > Label[end]; > prcnt[[n]] > > > > thank you for your assistance, > Mr. Glenn J. Kuhaneck > -- DrMajorBob at yahoo.com
- References:
- looping
- From: glenn kuhaneck <mcguyver128@yahoo.com>
- looping