This is my final attempt. :) which is my final assignment. The problem from my previous script was the "is, so I changed it to "==". I successfully execute the replies properly :3 I added float to my percentage so it will print out "40.0%" instead of "40%". I defined the numberofquestions as len(QandAList) over here so it will not have error. It went successfully well. :3 The main problem was the parameter part. I have to pass my lists into my percentage so the equation can be executed. Now this is the final script for my assignment 1. :3
Python Programming Days
Tuesday, 3 December 2013
Fifth Attempt: Use of "Len"
This is the fifth attempt on the script. I managed to add in the percentage and a new statement called "elif". Elif statements is used for adding another condition. As you can see in the grade function. I changed the index<5 to len(QandAList). Len is the length of the list. It is used for lists to calculate length of the lists. So if I have 10 questions it will loop for 10 questions. It varies. I still haven't put in the float in my percentage. I ha problems with my "elif" statements, it just won't work well. So for the invalid selection to be valid, I had to type out elif(UserAns is "A") so on... It works! Thanks to my friend's help. ^^
My "numberofquestions" is not defined. And my invalid selection problem is still there... :(
Third Attempt: The "while" loop
In this script, I did the "while loop". While loop is actually related to English programming language. It actually is logical. A while loop statement in Python programming language repeatedly executes a target statement as long as the given condition is true. For example: "While a tea is hot, add some ice to cool it. Generally for loop is for specific number of iterations as for while loop, it is valid if the conditions are true. I added index<5 so it reads my questions.
The following is the F5 module:
But this script is unsuccessful(see on the left), everything I typed in will be invalid. =.= This is a failed script.
Second Attempt: Introducing lists and index!
Screenshot sucks! But never-mind. :) Let's go on to my second progress on my script. This time round there was a big change in my script. >.< I changed to a brand new format. This time, I added grade and percentage functions with parameters. However, this script cannot be run. :(
The following is the F5 module of my script:
As you can see, there was an error in my program: "unindent does not match any outer indentation level". At this point, I took quite some time to think about it...
There is something wrong with my spacing behind the "if" statement but I did not know what went wrong. So I was kind of frustrated. >.<
Anyway, for this script, I added lists of options. For example:
OptList = ["A. Purple Orchid\t B. Miss Vanda Jouqium\t C. Vanda Miss Joaqium\t D. Vanda Miss Joaquim","A. Forever\t B. 4\tC. 12\tD. 3","A. Primates\t B. Dolphins\t C. Elephants\t D. Canines","A. Canada\t B. Ukraine\t C. Norway\t D. Vatican City","A. 20\tB. 24\tC. 0\tD. 14"]
The "/t" is to make the options arrangement to be in this format:
1. What is the full name of the national flower in Singapore?
A. Purple Orchid
B. Miss Vanda Jouqium
C. Vanda Miss Joaqium
D. Vanda Miss Joaquim
See, it prints out nicely!
The next thing that I changed was the index an score. To make the script run, I changed the index = 0 first. And after a question is asked and answered correctly, I included index += 1 below so that it actually goes to the other question. If it's wrong, question will be asked again. (there will be no index += under the else statement. At this stage, I was still not introduced to "while" or "for" loops yet, so I was stuck with the basic one.
First Ever Attempt :)
Sorry for the bad resolution. >.<
So this is my first ever attempt on the assignment. :3 This script can be executed but this way is an easy way out for Python Language.
When I first started out, I thought Python was going to be very simple. I heard rumors about Python being the "highest" programming language. ("Highest" referring to be the simplest). However, I was wrong. Python is not that simple as it looks. When you get to another further section of Python, it gets tougher.
This script shows the "easy" version of the quiz. This is basic and easy to understanding. You can just print your questions and answers out individually. For example, there will be 2 functions [checkquestions() and askquestions()] for each question. This is considered long-winded. Another thing is that there is no main() function for this format. At this point, I did not know what is "str.lower" or "str.upper". So I added [Answer == "A" or "a"] which is actually quite hard-coded. I knew how to do 'list' so I did a list for every single question which is super long-winded and boring looking.
The following is the running module of this script:
I have not put in my grading and percentage functions inside so there was just questions, options and replies. :) My introduction works well :)
Subscribe to:
Posts (Atom)

















