How can I write a program that will automatically generate an sample examination for example The user will be prompted to supply four categories of questions to be included in the a 6 question exam from the following list: Loops,Functions,Decisions,Data Types,Built-in functions, Recursion, Algorithms, Top-down design,Objects.
I also need to prompt the user to supply the total marks of the exam and also prompt the user for how many multiple questions in the exam.
The Sample questions, their category, their value (number of marks) and whether they are multiple choice questions are stored in a Question file that I need to open to read all of the questions. Then the program should read the Question file and randomly select questions according to what the user has entered.
The file format is a text file in notepad.
Here is what is in the text file:Loops Questions
Mutiple Choice Questions
Loops Questions
1. Which of the following is not a part of the IPO pattern?
a)Input b)Program c)Process d)Output
2. In Python, getting user input is done with a speical expression called.
a)for b)read c)simultaneous assignment d)input
Function Questions
3. A Python function definition begins with
a)def b)define c)function d)defun
4.A function with no return statement returns
a)nothing b)its parameters c)its variables d)None
Decison Questions
5. An expression that evaluates to either true or fales is called
a)opertional b)Boolean c)simple d)compund
6.The literals for tpe bool are
a)T,F b)True,False c)true,false d)procrastination
DataTypes Questions
7. Which of the following is not a Python type-conversiion function?
a)float b)round c)int d)long
8.The number of distinct values that can be represneted using 5 bits is
a)5 b)10 c)32 d)50
Built-in Functions
9.The part of a program that uses a function is called the
a)user b)caller c)callee d)statement
10.A function can send output back to the program with a(n)
a)return b)print c)assignment d)SASE
Recusrsion
11.Recursions on sequnece often use this as a base case:
a)0 b)1 c)an empty sequence d)None
12.The recursive Fibonacci function is inefficient because
a)it does many repeated computations b)recursion is inherently ineffcient compared to iteration
c)calcualting Fibonacci numbers is intreactable d)fibbing is morally wrong
Algorithms
13.An algorithm is like a
a)newspaper b)venus flytrap c)drum d)recipe
14.Which alogorithm requires time directly proportional to the size of the input?
a)linear search b)binary search c)merge sort d)selction sort
Top-down design
15.Which of the following is not one of the fundamental characteristics of object-oriented design/programming?
a)inheritance b)polymorphism c)generally d)encapsulation
Objects
16.What graphics class would be best for drawing a square?
a)Square b)Polygon c)Line d)Rectangle
17.A user interface organized around visual elements and users actions is called a (n)
a)GUI b)application c)windower d)API
This is the code I have gone so far any ideas?
def main():
infile = open("30075165.txt","r")
categories = raw_input("Please enter the four categories that are in the exam: ")
totalmarks = input("Please enter the total marks in the exam: ")
mc = input("Please enter the amount of multiple choice questions in the exam: ")
main()