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!

Leave a comment