Thread Simples lern-script
(9 answers)
Opened by Gast at 2007-08-14 15:38
hallo, ich bastel gerad an nem lern-script rum, soll einfach fragen stellen und dann halt ermitteln ob richtig oder falsch... simpel halt :)
hier mein code: Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 #!/usr/bin/perl # # Simple learning Script # by F.Luettgens # ####################################### use strict; use warnings; my $maxtries = '3'; my $dbfile = "learnIT.db"; open(DB, "<$dbfile"); my @db = <DB>; system("clear"); foreach (@db) { my $tries = 0; my @package = split(/.:./, $_); my $question_nr = $package[1]; my $question_question = $package[2]; my $question_answer = $package[3]; QUESTION: print("\#$question_nr $question_question\n"); print("Answer: "); my $answer = <STDIN>; if ($answer eq $question_answer) { print("Thats correct!\n"); } else { $tries++; if ($tries eq $maxtries) { print("Wrong answer!\nThe right one is $question_answer\n"); } else { print("Thats wrong, try again!\n"); goto QUESTION; } } } die db: [nop].:.1.:.What is 1+1?.:.2 .:.2.:.Whats the airspeed velocity of an unladen swallow?.:.African or European? .:.3.:.How many fingers are on a single hand?.:.4 .:.4.:.Is this question dumb?.:.Yes[/nop] Output: [nop]#1 What is 1+1? Answer: 1 Thats wrong, try again! #1 What is 1+1? Answer: 2 Thats correct! #2 Whats the airspeed velocity of an unladen swallow? Answer: 3 Thats wrong, try again! #2 Whats the airspeed velocity of an unladen swallow? Answer: African or European? Thats correct! #3 How many fingers are on a single hand? Answer: 4 Thats correct! #4 Is this question dumb? Answer: Yes Thats correct! [/nop] |