1 2 3 4 5 6 7 8 9 10 11 12 13 14 | set cards [list "Queen of Hearts" "3 of Clubs" "9 of Spades" \ "Ace of Hearts" "5 of Diamonds"] # Ask user for what to search puts -nonewline "Card for which to search (such as King, Spade, or 9): " flush stdout gets stdin card # Loop until user inputs a matching card while {[set index [lsearch $cards *[string totitle $card]*]] < 0} { puts "No such card. Please try again." puts -nonewline "Card for which to search (such as King, Spade, or 9): " flush stdout gets stdin card } # Show the match puts "Matched the [lindex $cards $index]" |
-
upload with new input
-
result: Success time: 0.03s memory: 5272 kB returned value: 0
Card for which to search (such as King, Spade, or 9): Matched the Queen of Hearts
-
result: Success time: 0.03s memory: 5272 kB returned value: 0
spade
Card for which to search (such as King, Spade, or 9): Matched the 9 of Spades
-
result: Runtime error time: 0.03s memory: 5272 kB signal: -1
king
Card for which to search (such as King, Spade, or 9): No such card. Please try again. Card for which to search (such as King, Spade, or 9):
wrong # args: should be "flush channelId" while executing "flush stdout gets stdin card" ("while" body line 4) invoked from within "while {[set index [lsearch $cards *[string totitle $card]*]] < 0} { puts "No such card. Please try again." puts -nonewline "Card for which to search (..." (file "prog.tcl" line 8) -
result: Success time: 0.03s memory: 5272 kB returned value: 0
Card for which to search (such as King, Spade, or 9): Matched the Queen of Hearts



