LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-05-2012, 11:01 AM   #1
emanWASUNAVAILABLE
LQ Newbie
 
Registered: Nov 2012
Location: behind one of 9 terminals
Distribution: backtrack
Posts: 3

Rep: Reputation: Disabled
Post Perl "Quizilla" Program with random answer generation


okay so i liked, its not really "random" what answer it is for each quiz, but its damn close considering im only on chapter 4 of perl! anyways, enjoy and edit to your hearts content, but please refrain from defacing the original banner's name "quizilla" or removing my tag "eman" as the open source is for altering the functional portions of the program not passing creation rights as your own =)

p.s. feel free to add your own signature to it if you edit it in any way, enjoi.


#!/usr/bin/perl

use 5.010;

&loading_screen;

sub loading_screen {

print "\n\n\n";
print " QQQQQQQQQQ UUU UUU IIIIIIIIII ZZZZZZZZZZ IIIIIIIIII LLL LLL AAAAAAAAAA\n";
print " QQQQQQQQQQ UUU UUU IIIIIIIIII ZZZZZZZZZZ IIIIIIIIII LLL LLL AAAAAAAAAA\n";
print " QQQ QQQ UUU UUU III ZZZZ III LLL LLL AAA AAA\n";
print " QQQ QQQ UUU UUU III ZZZZ III LLL LLL AAA AAA\n";
print " QQQ QQQ UUU UUU III ZZZZ III LLL LLL AAAAAAAAAA\n";
print " QQQ QQQ UUU UUU III ZZZZ III LLL LLL AAAAAAAAAA\n";
print " QQQ QQQ UUU UUU III ZZZZ III LLL LLL AAA AAA\n";
print " QQQ QQQ UUU UUU III ZZZZ III LLL LLL AAA AAA\n";
print " QQQQQQQQQQ UUUUUUUUUU IIIIIIIIII ZZZZZZZZZZ IIIIIIIIII LLLLLLLLLL LLLLLLLLLL AAA AAA\n";
print " QQQQQQQQQQQQ UUUUUUUUUU IIIIIIIIII ZZZZZZZZZZ IIIIIIIIII LLLLLLLLLL LLLLLLLLLL AAA AAA\n";
print " QQQQ\n";
print "\t\t\t\t\t\t\t\t\t\t\t\tby eman\n\n\n\n";
print " Choose a test:\n";
print " 1 - Perl\n";
print " 2 - 802.11\n";
print " 3 - Network Fundamentals\n";
print " \n\n\n\n\n\n\n\n\n\nTest: ";

chomp( $get_test = <STDIN> );

if ( $get_test != 1 )
{
if ( $get_test != 2 )
{
if ( $get_test != 3 )
{
print "\n ...follow directions...";
&loading_screen;
}
}
}

if ( $get_test == 1 )
{
print "...test 1 unavailable...";
&loading_screen;
}
if ( $get_test == 2 )
{
print "...test 2 unavailable...";
&loading_screen;
}
if ( $get_test == 3 )
{
print "\n\n\n\t\t\t\t\t\t\tNework Fundamentals Quiz 1.0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
&network_fundamentals;
}
}

sub network_fundamentals
{
$question_1_time = 0;
$question_2_time = 0;
$question_2_answer = 0;
$question_1_answer = 0;

$number_correct = 0;

$is_question_1_correct = &question_1( $question_1_answer );
$number_correct += $is_question_1_correct;
$wrong[0] = $is_question_1_correct;

$is_question_2_correct = &question_2( $question_2_answer );
$number_correct += $is_question_2_correct;
$wrong[1] = $is_question_2_correct;

print "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\tREVIEW\n\n";
print "You got " . $number_correct . " of 2 correct!\n\n";

foreach ( @wrong )
{
$count += 1;

if ($wrong[( $count - 1 )] == '0')
{
print "Question $count was wrong, the correct answer was ABC\n";
}
}

print "\n";
}

sub question_1 {

my $answer;
my @a;
my @b;
my @c;
my @d;

$a_is_right[5] = "An identified sender and reciever";
$a_is_right[1] = "An agreed-upon speed and timing of deliver";
$a_is_right[2] = "Confirmation or acknowledgement requirements";
$a_is_right[3] = "Common langauge and grammar";
$a_is_right[4] = "An aggreed-upon method of communicating";

$a_is_wrong[4] = "The weather";
$a_is_wrong[1] = "Fat chicks";
$a_is_wrong[2] = "Santa";
$a_is_wrong[3] = "Space";

$b_is_right[4] = "An identified sender and reciever";
$b_is_right[5] = "An agreed-upon speed and timing of deliver";
$b_is_right[1] = "Confirmation or acknowledgement requirements";
$b_is_right[2] = "Common langauge and grammar";
$b_is_right[3] = "An aggreed-upon method of communicating";

$b_is_wrong[3] = "The weather";
$b_is_wrong[4] = "Fat chicks";
$b_is_wrong[1] = "Santa";
$b_is_wrong[2] = "Space";

$c_is_right[3] = "An identified sender and reciever";
$c_is_right[4] = "An agreed-upon speed and timing of deliver";
$c_is_right[5] = "Confirmation or acknowledgement requirements";
$c_is_right[1] = "Common langauge and grammar";
$c_is_right[2] = "An aggreed-upon method of communicating";

$c_is_wrong[2] = "The weather";
$c_is_wrong[3] = "Fat chicks";
$c_is_wrong[4] = "Santa";
$c_is_wrong[1] = "Space";

$d_is_right[2] = "An identified sender and reciever";
$d_is_right[3] = "An agreed-upon speed and timing of deliver";
$d_is_right[4] = "Confirmation or acknowledgement requirements";
$d_is_right[5] = "Common langauge and grammar";
$d_is_right[1] = "An aggreed-upon method of communicating";

$d_is_wrong[3] = "The weather";
$d_is_wrong[4] = "Fat chicks";
$d_is_wrong[1] = "Santa";
$d_is_wrong[2] = "Space";

$question_number += 1;
$question_1_time += 1;

print "\nQuestion $question_number of 2";
print "\n\nSome of the protocols required for communication to occure the presece of(choose three):\n\n";

if ( $question_1_time == 5 )
{
print "A. $a_is_right[$question_1_time] \n" . "B. $b_is_wrong[2] \n" . "C. $c_is_right[$question_1_time] \n" . "D. $d_is_right[$question_1_time]";
print "\nAnswer: ";
chomp($answer = <STDIN>);

$question_1_time = 0;

if ( $answer eq 'acd' | 'ACD' )
{
return 1;
} else {
return 0;
}
} else {
if ( $question_1_time == 1 )
{
print "A. $a_is_right[$question_1_time] \n" . "B. $b_is_right[$question_1_time] \n" . "C. $c_is_right[$question_1_time] \n" . "D. $d_is_wrong[$question_1_time]\n";

print "\nAnswer: ";
chomp($answer = <STDIN>);

if ( $answer eq 'abc' | 'ABC' )
{
return 1;
}
else {
return 0;
}
}
if ( $question_1_time == 2 )
{
print "A. $a_is_wrong[$question_1_time] \n" . "B. $b_is_right[$question_1_time] \n" . "C. $c_is_right[$question_1_time] \n" . "D. $d_is_right[$question_1_time]\n";

print "\nAnswer: ";
chomp($answer = <STDIN>);

if ( $answer eq 'bcd' | 'BCD' )
{
return 1;
}
else {
return 0;
}
}
if ( $question_1_time == 3 )
{
print "A. $a_is_right[$question_1_time] \n" . "B. $b_is_wrong[$question_1_time] \n" . "C. $c_is_right[$question_1_time] \n" . "D. $d_is_right[$question_1_time]\n";

print "\nAnswer: ";
chomp($answer = <STDIN>);

if ( $answer eq 'acd' | 'ACD' )
{
return 1;
}
else {
return 0;
}
}
if ( $question_1_time == 4 )
{
print "A. $a_is_right[$question_1_time] \n" . "B. $b_is_right[$question_1_time] \n" . "C. $c_is_wrong[$question_1_time] \n" . "D. $d_is_right[$question_1_time]\n";

print "\nAnswer: ";
chomp($answer = <STDIN>);

if ( $answer eq 'abd' | 'ABD' )
{
return 1;
}
else {
return 0;
}
}
}

}

sub question_2 {

my $answer;

# right answers

my $a = "An identified sender and reciever";
my $b = "An agreed-upon speed and timing of deliver";
my $c = "Confirmation or acknowledgement requirements";
my $d = "Common langauge and grammar";
my $e = "An aggreed-upon method of communicating";

# wrong answers

my $f = "The weather";
my $g = "Fat chichks";
my $h = "Santa";
my $i = "Space";

$question_number += 1;

print "\nQuestion $question_number of 2";
print "\n\nSome of the protocols required for communication to occure the presece of(choose three):\n\n";

print "A. $a\nB. $b\nC. $c\nD. $g\n";
print "\nAnswer: ";
chomp($answer = <STDIN>);

if ( $answer eq 'abc' | 'ABC' )
{
return 1;
}
else {
return 0;
}
}

Last edited by emanWASUNAVAILABLE; 11-05-2012 at 11:03 AM.
 
Old 11-05-2012, 11:07 AM   #2
emanWASUNAVAILABLE
LQ Newbie
 
Registered: Nov 2012
Location: behind one of 9 terminals
Distribution: backtrack
Posts: 3

Original Poster
Rep: Reputation: Disabled
Im not sure why it altered the banner like that...youll have to "space over the letters" till it forms QUIZILLA
 
Old 11-07-2012, 06:40 AM   #3
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
It's interesting to see, which nonsense in Perl can work when one omits
Code:
use strict;
use warnings;
What you are writing (here and in your other thread) isn't Perl5 but Perl4. If you really want to learn Perl:

1. put the above two lines to the top of your code (dircetly below #!/usr/bin/perl)
2. run your program
3. Open a terminal (use Linux) and execute
Code:
perldoc -q variables
4. Read carefully and find out, what all the error- and warningmessages mean.

Markus
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl: how to save an e-mail attachment on disk keeping the "&" character (no "%26"!!) d1s4st3r Programming 5 09-29-2010 09:30 PM
Perl - Can't use string ("html") as an ARRAY ref while "strict refs" OldGaf Programming 9 08-11-2009 11:14 AM
"Failed Dependency error" while installing RPM for "DateTime" perl modules giridhargopal.cj Linux - Newbie 7 11-19-2008 12:05 AM
problem "make"ing gtk+ "/usr/bin/env: perl -w" caid Linux - Newbie 8 07-29-2005 04:51 AM
LFS 4.1: Stalled at Perl, "missing seperator" error from "make" SparceMatrix Linux From Scratch 1 06-07-2003 03:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration