HOW TO MAKE A MULTIPLE-CHOICE PROGRAM

Hello, my name is Manuel and I run ManyProgramming™. Today we will be making a functional Multiple-Choice program. I will be making a quiz with five Multiple-Choice questions. At the end it will show me my score.

Today I will be showing you pretty complex and diverse multiple-choice quiz that has a lot of different features. I will try to split the quiz up into small diverse parts which we can then put completely together at the end. I will also put up a copy of the completed quiz! WARNING! WHEN I USE THE ‘#’ THAT MEANS THAT PYTHON ONLY TAKES IT IN AS TEXT AND DOESN’T PROCESS IT!

Firstly, we’ll start off with the beginning part. 

print ('WELCOME TO THE MULTIPLE CHOICE TEST\n')

name = input('WHAT IS YOUR NAME? ')

print ('\nHI THERE ' + name + '! LET''S PLAY A GAME!\n')

print ('\n-----------------------------------------------------------\n')

score = 0

First it will say ‘WELCOME TO THE MULTIPLE CHOICE TEST’, then, it will ask you for your name. Then after you put your name in it will say ‘HI THERE What_ever_your_name_is! LET’S PLAY A GAME! It will then have a line that splits the welcoming & the actual questions.

Secondly, we will do the questions.

print ('QUESTION 1: WHAT IS THE LARGEST OCEAN IN THE WORLD?\n')
print ('A. The Indian Ocean')
print ('B. The Pacific Ocean')
print ('C. The Atlantic Ocean')
print ('')

Q1answer = "B"
Q1response= input('Your answer : ')

if (Q1response != Q1answer):
print ('Sorry, that is incorrect! The answer was B')
else:
print ('Well done! ' + Q1response + ' is correct!')
score = score + 1
print ('Your current score is ' + str(score) + ' out of 5')
print ('\n-----------------------------------------------------------\n')

Now this is the question. The question will have three options as answers. You have to type the letter that you think is the correct answer; if you get the answer right, then it will say ‘Well done! Whatever_letter_you_said_correctly is correct!’but, if you get it wrong, then it will say that it is incorrect and will tell you the right answer. If you want to have multiple questions, then you just copy everything I wrote above multiple times and just edit the questions and answers. At the end the score will be +1 every time you get the answer correct! And, at the very end, it will tell you your current score and then put a line, separating the different questions!

Lastly, the part at the end is probably the easiest to understand. What you see below tells Python that it needs to print the score you got, in my case out of five because I have 5 questions, but you can decide out of how much your score should be. At the bottom, it has a line which says that the quiz is ended (Not to Python because it doesn’t take that in but to you).

print ('Your total score is ' + str(score) + ' out of 5')
print ('\n-----------------------------------------------------------\n')

# Thank you for taking part in my Quiz!! 

Now if you put all this together, then you will have a very long program and as a programmer, you want to save as much space as you can so I will now show you how to shorten everything. It will be the same, basic principal as the program we did last blog; as you’ll see below.

def question1(Quest, Ans1, Ans2, Ans3, Ans):
    global score
    correct_answer=False
    for counter in range (3):
        x=input(Quest)
        if x.upper()==Ans.upper():
            print('Well Done, You got it Correct, +1 Point')
            score+=1
            correct_answer=True
            break
        else:
            print('Sorry, You got it Incorrect, Better luck Next Time! ')
    if not correct_answer:
        print('The Answer was',Ans)

print('ManyProgramming_Quizquam','\nPlease type in the letter of your selected choice!')
score=0
question1('What is the largest Animal on Earth?','\nA= Blue Whale','\nB= Elephant','\nC= Humpback Whale,' A')
question1('What is the fastest car on Earth?','\nA= Muscle Cars','\nB= Ferrari','\nC= Koenigsegg',' C')
question1('What is the most Deadly Spider on Earth?','\nA= Tarantula','\nB= Black Widow Spider','\nC= Daddy Long Legs',' B')
print('\n-----------------------------------------------------------------)
print('\nCongratulations, Your Total Score was', score)

This way you can add as many questions as you would like by simply adding a line that tells the information of the question, as I have done above. The idea is very simple; it uses a function which determines whether the answer is right of wrong. I also have written all the different objects and used ‘\n’ to tell Python that the three options for the multiple-choice test will be on separate lines. It is also the same principal as the first program I made; if you didn’t read it then Click Here to Open the Blog!!

Thank you for reading my blog. I hope you have a wonderful day. If you want to have the quiz, email programmingmany@gmail.com and I will send you the quiz and how to load it. Also, get ready for my Christmas blog. I will post at 7:00pm on Monday the 24th of December! If you would like to see my book reviews blog then Click Here!

MY FIRST FUNCTIONAL PROGRAM!

Hello, my name is Manuel and I run ManyProgramming™. Today we will be making our first functional program. I will be making a quiz with three simple questions. At the end it will show me my score.

Firstly I need to open my Command Prompt and my Text Editor. I am using a very standard text editor for Windows but any will do. How to get it running: Save the Text in a Text Editor in a directory under your C drive. To start the program you need to type into Python, “exec(open(‘C:\\Wherever_you_have_saved_it\\ ManyProgramming_Quizquam.py’).read())”.When you save the file, you need to write .py next to the name e.g. The name is: ManyProgramming so I save it as ManyProgramming.py. I used ManyProgramming_Quizquam.py because that is what I called my file. 

print(‘ManyProgramming_Quizquam’)
score=0
for counter in range (3):
    x=input(‘What is the Largest Animal on Earth? ‘)
    if x.upper()==’BLUE WHALE’:
        print(‘Well Done, You got it Correct, +1 Point’)
        score+=1
        break
    else:
        print(‘Sorry, You got it Incorrect, Better luck Next Time! ‘)
if score > 0:
    print(‘Your Score is’, score)
else:
    print(‘The Answer was Blue Whale’)

The Idea of the Program: So, at the Beginning, it will say ManyProgramming_Quizquam. Then it will ask the question ‘What is the largest Animal on Earth?’ You will have to answer on the same line; if you get it correct it will show you your score (On this version there is only one question), however, it you get it wrong you will have two more chances, so, three chances all together.

The ‘x.upper()’ part of the text means that whatever pattern of capitals and lower cases there are, the answer will always be converted to upper and the spelling will be correct.

If, after the three chances, you get it wrong , then it will say ‘Sorry, You got it Incorrect, Better luck Next Time’. The idea of the program is to make a quiz for whoever asks it to. This is one of the simplest programs you can get.

However, if you want to have more questions you need to copy the entire program as many times as the number of questions you want to ask, editing the text in each part as you go.

The next text uses a function to re-use the program again, and again: 

def anything_you_want(Quest, Anything_you_want):
    global score
    correct_answer=False
    for counter in range (3):
        x=input(Quest)
        if x.upper()==Ans.upper():
            print(‘Well Done, You got it Correct, +1 Point’)
            score+=1
            correct_answer=True
            break
        else:
            print(‘Sorry, You got it Incorrect, Better luck Next Time! ‘)
    if not correct_answer:
        print(‘The Answer was’,Ans)

print(‘ManyProgramming_Quizquam’)
score=0
question1(‘What is the largest Animal on Earth?’, ‘Blue Whale’)
question1(‘What is the fastest car on Earth?’, ‘Koenigsegg’)
question1(‘What is the most Deadly Spider on Earth?’, ‘Black Widow Spider’)
print(‘\nCongratulations, Your Total Score was’, score)

Now this is one of our more complex and diverse programs on the beginning stages of our blog. At the beginning it defines a function that can be re-used with different questions. The ‘for counter in range (3)’, like the other example, is telling Python to give you two more chances, so three chances in total. The next part tells Python that if you get the answer correct than you can move on to the next question but if you got it wrong, then you have to answer it again and a message telling you that you got it wrong will appear. The last part is telling you that you need to 

I have written three questions at the bottom which get asked on my program but you can make as many questions as you like and can call them whatever you want as long as, for now, it is a one word answer.

I really hope you have enjoyed this blog. Every view helps me a lot and if you have any questions contact: programmingmany@gmail.com. If you would like to see my book reviews blog, then Click Here!