[GWM] Presents a number of cards - you select Yes or No to check if your imagined number is there. After 5 answers the number you thought of is displayed. A classic automatic magic trick often used in Christmas Crackers. Unless you gave an incorrect answer. # 'magic' interactive eneration of magic cards trick global sum proc addresult {nres onoff nmax} { global sum if {$onoff == 1} { incr sum $nres } incr nres $nres puts "Result $sum $nres" makeCard $nmax $nres } proc showresult {} { global sum catch {destroy .t} {} ;# delete it. Same as clear. catch {destroy .byes} {} ; catch {destroy .bno} {} ; button .bguess -text "Your number was\n$sum" -command "runtrick 64" -font {Arial 32 bold} pack .bguess } proc makeCard {nmax ntest} { catch {destroy .bguess} {} ; catch {destroy .t} {} ;# delete it. Same as clear. catch {destroy .byes} {} ; catch {destroy .bno} {} ; if { $nmax >$ntest } { text .t -bg beige button .byes -text "Yes" -command "addresult $ntest 1 $nmax" button .bno -text "No" -command "addresult $ntest 0 $nmax" pack .t .byes .bno pack .byes .bno -side left .t insert end "Is your number in this set $ntest nmax $nmax:\n" set i 1 set nextnewl 10 while {$i<$nmax} { set frac [expr (($i/$ntest))] if {[expr $frac%2==1 ] } { .t insert end " $i" } incr i if {$i>$nextnewl} { .t insert end "\n" incr nextnewl 10 } } } else { showresult } } proc runtrick {nmax} { global sum set sum 0 makeCard $nmax 1 } set sum 0 runtrick 64 [Category Games]