Certainly! Below are 100 Grade 12 level multiple-choice math questions without answers. Following the questions, you'll find a Python script that can split these questions into 10 separate documents, each containing 10 questions numbered from 1 to 10.
Grade 12 Math Multiple-Choice Questions
1. What is the derivative of ( f(x) = 3x^4 - 5x^2 + 7 )?
- A) ( 12x^3 - 10x )
- B) ( 12x^3 + 10x )
- C) ( 12x^3 - 5x )
- D) ( 3x^3 - 5x )
2. If ( \lim_{{x \to 2}} \frac{x^2 - 4}{x - 2} ), what is the limit?
3. Solve for ( x ): ( e^{2x} = 7 ).
- A) ( \frac{1}{2} \ln(7) )
- B) ( 2 \ln(7) )
- C) ( \ln(7) )
- D) ( \ln(7)/2 )
4. The integral ( \int (4x^3 - 2x + 1) , dx ) is:
- A) ( x^4 - x^2 + x + C )
- B) ( x^4 - x^2 + x - C )
- C) ( x^4 + x^2 + x + C )
- D) ( x^4 - x^2 - x + C )
5. What is the solution to the differential equation ( \frac{dy}{dx} = y )?
- A) ( y = Ce^x )
- B) ( y = Ce^{-x} )
- C) ( y = Ce^{x^2} )
- D) ( y = C )
6. If ( \mathbf{A} = \begin{pmatrix} 2 & 3 \ 1 & 4 \end{pmatrix} ), what is the determinant of ( \mathbf{A} )?
7. Which of the following sequences is arithmetic?
- A) 2, 4, 8, 16, ...
- B) 5, 10, 15, 20, ...
- C) 3, 9, 27, 81, ...
- D) 1, 4, 9, 16, ...
8. What is the sum of the first 10 terms of the geometric series ( 3, 6, 12, \ldots )?
- A) 6147
- B) 3075
- C) 6144
- D) 3072
9. If ( \sin(\theta) = \frac{3}{5} ) and ( \theta ) is in the first quadrant, what is ( \cos(\theta) )?
- A) ( \frac{4}{5} )
- B) ( \frac{3}{4} )
- C) ( \frac{5}{3} )
- D) ( \frac{5}{4} )
10. The matrix multiplication ( \begin{pmatrix}1 & 2\3 & 4\end{pmatrix} \times \begin{pmatrix}5 & 6\7 & 8\end{pmatrix} ) results in:
- A) ( \begin{pmatrix}19 & 22\43 & 50\end{pmatrix} )
- B) ( \begin{pmatrix}17 & 20\39 & 46\end{pmatrix} )
- C) ( \begin{pmatrix}12 & 16\28 & 36\end{pmatrix} )
- D) ( \begin{pmatrix}13 & 18\35 & 48\end{pmatrix} )
11. Simplify ( \log_b(b^3) ).
- A) 3
- B) ( b^3 )
- C) ( \log(b) )
- D) ( 3b )
12. What is the inverse function of ( f(x) = 2x + 5 )?
- A) ( f^{-1}(x) = \frac{x - 5}{2} )
- B) ( f^{-1}(x) = 2x - 5 )
- C) ( f^{-1}(x) = \frac{2x + 5}{2} )
- D) ( f^{-1}(x) = \frac{5 - x}{2} )
13. Find the roots of the quadratic equation ( x^2 - 6x + 8 = 0 ).
- A) 2 and 4
- B) 3 and 3
- C) 1 and 7
- D) -2 and -4
14. If ( f(x) = \ln(x) ), find ( f'(x) ).
- A) ( \frac{1}{x} )
- B) ( \ln'(x) )
- C) ( x )
- D) ( \frac{1}{\ln(x)} )
15. Evaluate the limit ( \lim_{{x \to 0}} \frac{\sin(x)}{x} ).
- A) 0
- B) 1
- C) Undefined
- D) Infinity
16. What is the sum of the interior angles of a hexagon?
- A) ( 720^\circ )
- B) ( 600^\circ )
- C) ( 540^\circ )
- D) ( 360^\circ )
17. Determine the convergence of the series ( \sum_{n=1}^{\infty} \frac{1}{n^2} ).
- A) Diverges
- B) Converges
- C) Conditionally converges
- D) Does not converge
18. What is the general solution to the equation ( x^3 - 1 = 0 )?
- A) ( x = 1 )
- B) ( x = 1, x = -1 )
- C) ( x = 1, x = \frac{-1 \pm i\sqrt{3}}{2} )
- D) ( x = \frac{1 \pm \sqrt{3}}{2} )
19. If ( \mathbf{v} = \begin{pmatrix}2\3\end{pmatrix} ), what is ( |\mathbf{v}| ) (the magnitude of ( \mathbf{v} ))?
- A) ( \sqrt{13} )
- B) ( \sqrt{9} )
- C) ( \sqrt{4} )
- D) ( \sqrt{25} )
20. Solve for ( x ) in the equation ( \tan(x) = \sqrt{3} ) within ( 0 \leq x < 2\pi ).
- A) ( \frac{\pi}{6}, \frac{7\pi}{6} )
- B) ( \frac{\pi}{3}, \frac{4\pi}{3} )
- C) ( \frac{\pi}{4}, \frac{5\pi}{4} )
- D) ( \frac{\pi}{2}, \frac{3\pi}{2} )
21. What is the eigenvalue of the matrix ( \begin{pmatrix}4 & 1\2 & 3\end{pmatrix} )?
- A) 5, 2
- B) 6, 1
- C) 3, 4
- D) 7, 0
22. Find the area under the curve ( y = x^2 ) from ( x = 0 ) to ( x = 3 ).
23. If ( a_n = \frac{2n + 3}{n - 1} ), find ( \lim_{n \to \infty} a_n ).
- A) 0
- B) 2
- C) Undefined
- D) Infinity
24. Determine the horizontal asymptote of ( f(x) = \frac{3x^2 - 2x + 1}{6x^2 + x - 4} ).
- A) ( y = \frac{1}{2} )
- B) ( y = \frac{3}{6} )
- C) ( y = 0 )
- D) No horizontal asymptote
25. What is the integral ( \int \frac{1}{x} , dx )?
- A) ( \ln|x| + C )
- B) ( \frac{1}{x^2} + C )
- C) ( e^x + C )
- D) ( x + C )
26. Simplify ( (2x^3)^2 ).
- A) ( 4x^6 )
- B) ( 4x^5 )
- C) ( 4x^9 )
- D) ( 2x^6 )
27. What is the sum of the infinite geometric series ( \sum_{n=0}^{\infty} \left(\frac{1}{2}\right)^n )?
- A) 1
- B) 2
- C) 0.5
- D) Infinity
28. Solve the system of equations:
[
\begin{cases}
2x + 3y = 12 \
x - y = 3
\end{cases}
]
- A) ( x = 3, y = 1 )
- B) ( x = 4, y = 2 )
- C) ( x = 5, y = 1 )
- D) ( x = 6, y = 0 )
29. What is the Taylor series expansion of ( e^x ) around ( x = 0 )?
- A) ( \sum_{n=0}^{\infty} \frac{x^n}{n!} )
- B) ( \sum_{n=1}^{\infty} \frac{x^n}{n} )
- C) ( \sum_{n=0}^{\infty} \frac{n!}{x^n} )
- D) ( \sum_{n=0}^{\infty} x^n )
30. If ( f(x) = x^3 - 3x + 2 ), find ( f(1) ).
31. What is the limit ( \lim_{{x \to \infty}} \frac{5x^3 - x + 2}{2x^3 + 3x^2 - 1} )?
- A) ( \frac{5}{2} )
- B) ( \frac{2}{5} )
- C) ( \infty )
- D) 0
32. Determine the vertex of the parabola ( y = 2x^2 - 4x + 1 ).
- A) ( (1, -1) )
- B) ( (1, 3) )
- C) ( (2, -3) )
- D) ( (2, 3) )
33. If ( f(x) = \frac{1}{x} ), find ( f^{-1}(x) ).
- A) ( f^{-1}(x) = x )
- B) ( f^{-1}(x) = -x )
- C) ( f^{-1}(x) = \frac{1}{x} )
- D) ( f^{-1}(x) = x^2 )
34. What is the solution to the inequality ( x^2 - 5x + 6 < 0 )?
- A) ( 2 < x < 3 )
- B) ( x < 2 ) or ( x > 3 )
- C) ( x > 2 ) and ( x < 3 )
- D) ( x = 2 ) or ( x = 3 )
35. Evaluate the derivative ( \frac{d}{dx} \left( \sin(x) \cdot e^x \right) ).
- A) ( \cos(x) \cdot e^x )
- B) ( \sin(x) \cdot e^x )
- C) ( e^x (\cos(x) + \sin(x)) )
- D) ( e^x (\cos(x) - \sin(x)) )
36. What is the volume of a sphere with radius ( r )?
- A) ( \frac{4}{3}\pi r^3 )
- B) ( 4\pi r^2 )
- C) ( \frac{1}{2}\pi r^2 )
- D) ( 2\pi r^3 )
37. Find the inverse Laplace transform of ( \frac{1}{s^2} ).
- A) ( t )
- B) ( 1 )
- C) ( t^2 )
- D) ( e^t )
38. Compute the determinant of ( \begin{pmatrix} 1 & 2 & 3 \ 0 & 4 & 5 \ 1 & 0 & 6 \end{pmatrix} ).
39. What is the general term of the arithmetic sequence with first term 7 and common difference 3?
- A) ( a_n = 7 + 3n )
- B) ( a_n = 7 + 3(n-1) )
- C) ( a_n = 7 - 3n )
- D) ( a_n = 3n - 7 )
40. Solve for ( x ): ( \ln(x) = 2 ).
- A) ( x = e^2 )
- B) ( x = 2 )
- C) ( x = \ln(2) )
- D) ( x = e )
41. What is the cosine of the angle between vectors ( \mathbf{a} = \begin{pmatrix}1\2\3\end{pmatrix} ) and ( \mathbf{b} = \begin{pmatrix}4\5\6\end{pmatrix} )?
- A) ( \frac{32}{\sqrt{14} \cdot \sqrt{77}} )
- B) ( \frac{32}{\sqrt{14} + \sqrt{77}} )
- C) ( \frac{32}{14 \cdot 77} )
- D) ( \frac{32}{11} )
42. Evaluate the double integral ( \int_{0}^{1} \int_{0}^{1} (x + y) , dy , dx ).
- A) 1
- B) ( \frac{1}{2} )
- C) ( \frac{3}{2} )
- D) 2
43. Find the Maclaurin series for ( \cos(x) ).
- A) ( \sum_{n=0}^{\infty} \frac{(-1)^n x^{2n}}{(2n)!} )
- B) ( \sum_{n=0}^{\infty} \frac{x^{2n+1}}{(2n+1)!} )
- C) ( \sum_{n=1}^{\infty} \frac{x^n}{n!} )
- D) ( \sum_{n=0}^{\infty} \frac{x^n}{n!} )
44. If ( \mathbf{A} ) is a 3x3 matrix with rank 2, what is the nullity of ( \mathbf{A} )?
45. Determine the convergence of the series ( \sum_{n=1}^{\infty} \frac{(-1)^n}{n} ).
- A) Converges absolutely
- B) Converges conditionally
- C) Diverges
- D) Does not converge
46. What is the solution to the equation ( \log_2(x) + \log_2(x-2) = 3 )?
47. Find the derivative of ( f(x) = \tan^{-1}(x) ).
- A) ( \frac{1}{1 + x^2} )
- B) ( \frac{1}{x^2} )
- C) ( \frac{x}{1 + x^2} )
- D) ( \frac{1}{(1 + x^2)^2} )
48. If ( f(x) = x^4 - 4x^3 + 6x^2 - 4x + 1 ), factorize ( f(x) ).
- A) ( (x - 1)^4 )
- B) ( (x + 1)^4 )
- C) ( (x^2 - 2x + 1)^2 )
- D) ( (x - 1)^2(x^2 - 2x + 1) )
49. Compute the integral ( \int_{0}^{\pi/2} \sin(x) , dx ).
- A) 1
- B) 0
- C) ( \frac{\pi}{2} )
- D) ( \frac{\pi}{4} )
50. What is the sum of the first 5 terms of the arithmetic sequence with ( a_1 = 3 ) and ( d = 2 )?
51. Determine the radius of convergence for the power series ( \sum_{n=0}^{\infty} \frac{x^n}{n!} ).
- A) 1
- B) ( e )
- C) Infinity
- D) 0
52. Solve for ( y ) in terms of ( x ): ( y^2 = 4x ).
- A) ( y = 2\sqrt{x} )
- B) ( y = \sqrt{4x} )
- C) ( y = -2\sqrt{x} )
- D) All of the above
53. What is the Laplace transform of ( t )?
- A) ( \frac{1}{s^2} )
- B) ( \frac{1}{s} )
- C) ( \frac{1}{s^3} )
- D) ( \frac{2}{s^3} )
54. If ( f(x) = x^2 ) and ( g(x) = \sqrt{x} ), find ( (f \circ g)(x) ).
- A) ( x )
- B) ( x^{1/4} )
- C) ( x^{3/2} )
- D) ( \sqrt{x} )
55. Find the slope of the tangent line to ( y = x^3 ) at ( x = 2 ).
56. What is the probability of getting exactly 3 heads in 5 tosses of a fair coin?
- A) ( \frac{5}{32} )
- B) ( \frac{10}{32} )
- C) ( \frac{10}{16} )
- D) ( \frac{20}{32} )
57. Evaluate ( \int_{1}^{e} \frac{1}{x} , dx ).
- A) 1
- B) ( e - 1 )
- C) ( \ln(e) )
- D) Both A and C
58. If ( f(x) = e^{2x} ), find ( f''(x) ).
- A) ( 4e^{2x} )
- B) ( 2e^{2x} )
- C) ( e^{2x} )
- D) ( 8e^{2x} )
59. What is the application of the Fundamental Theorem of Calculus?
- A) It relates differentiation and integration.
- B) It provides methods for computing limits.
- C) It describes properties of sequences.
- D) It solves systems of equations.
60. Determine the continuity of ( f(x) = \frac{x^2 - 1}{x - 1} ) at ( x = 1 ).
- A) Continuous
- B) Discontinuous
- C) Removable discontinuity
- D) Infinite discontinuity
61. What is the solution set for ( \cos(x) = 0 ) in ( [0, 2\pi) )?
- A) ( x = \frac{\pi}{2}, \frac{3\pi}{2} )
- B) ( x = 0, \pi )
- C) ( x = \pi )
- D) ( x = \frac{\pi}{4}, \frac{3\pi}{4} )
62. Find the inverse function of ( f(x) = \frac{3x - 2}{x + 4} ).
- A) ( f^{-1}(x) = \frac{4x + 2}{3 - x} )
- B) ( f^{-1}(x) = \frac{2 + 4x}{3 - x} )
- C) ( f^{-1}(x) = \frac{2x + 4}{3 - x} )
- D) ( f^{-1}(x) = \frac{3x + 2}{4 - x} )
63. What is the second derivative of ( f(x) = \ln(x) )?
- A) ( -\frac{1}{x^2} )
- B) ( \frac{1}{x^2} )
- C) ( \frac{1}{x} )
- D) ( -\frac{1}{x} )
64. Compute the limit ( \lim_{x \to 0} \frac{e^x - 1}{x} ).
- A) 0
- B) 1
- C) Infinity
- D) Undefined
65. If ( f(x) = x^5 - 5x^4 + 10x^3 - 10x^2 + 5x - 1 ), factorize ( f(x) ).
- A) ( (x - 1)^5 )
- B) ( (x + 1)^5 )
- C) ( (x - 1)^2(x^3 + \ldots) )
- D) Cannot be factorized
66. What is the probability of rolling a sum of 7 with two six-sided dice?
- A) ( \frac{1}{6} )
- B) ( \frac{5}{36} )
- C) ( \frac{6}{36} )
- D) ( \frac{7}{36} )
67. Find the area between the curves ( y = x^2 ) and ( y = x + 2 ).
- A) ( \frac{9}{2} )
- B) ( \frac{15}{2} )
- C) ( \frac{21}{2} )
- D) ( \frac{25}{2} )
68. Determine the convergence of the integral ( \int_{1}^{\infty} \frac{1}{x} , dx ).
- A) Converges
- B) Diverges
- C) Conditionally converges
- D) Does not converge
69. What is the general solution to the recurrence relation ( a_n = 3a_{n-1} ) with ( a_0 = 2 )?
- A) ( a_n = 2 \cdot 3^n )
- B) ( a_n = 3^n )
- C) ( a_n = 2 + 3n )
- D) ( a_n = 2 \cdot n^3 )
70. Compute the dot product of ( \mathbf{u} = \begin{pmatrix}1\2\3\end{pmatrix} ) and ( \mathbf{v} = \begin{pmatrix}4\5\6\end{pmatrix} ).
71. Find the definite integral ( \int_{0}^{1} (3x^2 + 2x + 1) , dx ).
72. What is the solution to ( 2\cos^2(\theta) - 1 = 0 ) within ( 0 \leq \theta < 2\pi )?
- A) ( \frac{\pi}{4}, \frac{3\pi}{4}, \frac{5\pi}{4}, \frac{7\pi}{4} )
- B) ( \frac{\pi}{3}, \frac{2\pi}{3}, \frac{4\pi}{3}, \frac{5\pi}{3} )
- C) ( 0, \pi )
- D) ( \frac{\pi}{6}, \frac{5\pi}{6}, \frac{7\pi}{6}, \frac{11\pi}{6} )
73. Determine the null space of the matrix ( \mathbf{A} = \begin{pmatrix}1 & 2\2 & 4\end{pmatrix} ).
- A) ( \mathbf{0} )
- B) ( \begin{pmatrix}-2\1\end{pmatrix} )
- C) All vectors in ( \mathbb{R}^2 )
- D) There is no null space
74. If ( f(x) = x^2 + 1 ) and ( g(x) = 2x - 3 ), find ( (f + g)(x) ).
- A) ( 3x^2 - x - 2 )
- B) ( x^2 + 2x - 2 )
- C) ( x^2 + 2x - 1 )
- D) ( x^2 + 2x + 4 )
75. What is the value of ( \sum_{n=1}^{4} n! )?
76. Solve for ( x ): ( 2^{x} = 16 ).
77. What is the standard deviation of the data set ( {2, 4, 4, 4, 5, 5, 7, 9} )?
- A) 2
- B) 3
- C) 1.5
- D) 2.828
78. Determine the angle between the vectors ( \mathbf{a} = \begin{pmatrix}1\0\0\end{pmatrix} ) and ( \mathbf{b} = \begin{pmatrix}0\1\0\end{pmatrix} ).
- A) ( 0^\circ )
- B) ( 45^\circ )
- C) ( 90^\circ )
- D) ( 180^\circ )
79. What is the integral ( \int x e^x , dx )?
- A) ( (x - 1)e^x + C )
- B) ( x e^x - e^x + C )
- C) ( e^x (x + 1) + C )
- D) ( x e^x + e^x + C )
80. Find the Maclaurin series for ( \frac{1}{1 - x} ).
- A) ( \sum_{n=0}^{\infty} x^n )
- B) ( \sum_{n=1}^{\infty} x^n )
- C) ( \sum_{n=0}^{\infty} (-1)^n x^n )
- D) ( \sum_{n=1}^{\infty} (-1)^n x^n )
81. What is the rank of the matrix ( \mathbf{B} = \begin{pmatrix}1 & 2 & 3\4 & 5 & 6\7 & 8 & 9\end{pmatrix} )?
82. Solve the differential equation ( \frac{dy}{dx} = 3x^2 ) with ( y(0) = 4 ).
- A) ( y = x^3 + 4 )
- B) ( y = x^3 - 4 )
- C) ( y = 3x^2 + 4 )
- D) ( y = x^3 + C )
83. What is the probability of drawing a red card from a standard deck of 52 playing cards?
- A) ( \frac{1}{2} )
- B) ( \frac{1}{4} )
- C) ( \frac{3}{4} )
- D) ( \frac{13}{26} )
84. Determine the limit ( \lim_{x \to 1} \frac{x^3 - 1}{x - 1} ).
- A) 1
- B) 2
- C) 3
- D) Undefined
85. Find the area of a triangle with vertices at ( (0,0) ), ( (4,0) ), and ( (4,3) ).
86. If ( f(x) = \ln(x) ), find ( \int f(x) , dx ).
- A) ( x\ln(x) - x + C )
- B) ( e^x\ln(x) + C )
- C) ( \ln(x) + C )
- D) ( \frac{\ln(x)}{x} + C )
87. What is the solution to the equation ( \sqrt{x + 9} = x - 3 )?
- A) 6
- B) 5
- C) 4
- D) No solution
88. Compute the limit ( \lim_{x \to 0} \frac{1 - \cos(x)}{x^2} ).
- A) 0
- B) ( \frac{1}{2} )
- C) 1
- D) Undefined
89. What is the integral ( \int \frac{2}{x^3} , dx )?
- A) ( -\frac{1}{x^2} + C )
- B) ( \frac{1}{x^2} + C )
- C) ( -\frac{2}{x^2} + C )
- D) ( \frac{2}{x^2} + C )
90. Find the derivative of ( f(x) = \ln(\sin(x)) ).
- A) ( \cot(x) )
- B) ( \csc(x) )
- C) ( \tan(x) )
- D) ( \sec(x) )
91. What is the solution to ( \frac{d^2y}{dx^2} - 4\frac{dy}{dx} + 4y = 0 )?
- A) ( y = (C_1 + C_2x)e^{2x} )
- B) ( y = C_1e^{2x} + C_2e^{-2x} )
- C) ( y = C_1e^{4x} + C_2 )
- D) ( y = (C_1 + C_2x)e^{-2x} )
92. Determine the convergence of the series ( \sum_{n=1}^{\infty} \frac{n}{n^2 + 1} ).
- A) Converges
- B) Diverges
- C) Conditionally converges
- D) Does not converge
93. Find the equation of the line tangent to ( y = x^2 ) at ( x = 3 ).
- A) ( y = 6x - 9 )
- B) ( y = 6x + 9 )
- C) ( y = 3x - 9 )
- D) ( y = 3x + 9 )
94. What is the sum ( \sum_{k=0}^{n} \binom{n}{k} )?
- A) ( n )
- B) ( 2^n )
- C) ( n^2 )
- D) ( n! )
95. Solve for ( x ): ( \log(x) + \log(x-1) = 1 ).
- A) ( x = 1 )
- B) ( x = 2 )
- C) ( x = 10 )
- D) No solution
96. What is the Laplace transform of ( \sin(at) )?
- A) ( \frac{a}{s^2 + a^2} )
- B) ( \frac{s}{s^2 + a^2} )
- C) ( \frac{1}{s^2 + a^2} )
- D) ( \frac{a}{s + a} )
97. Evaluate the improper integral ( \int_{1}^{\infty} \frac{2}{x^3} , dx ).
- A) 1
- B) ( \frac{1}{2} )
- C) ( \frac{2}{x^2} \Big|_{1}^{\infty} )
- D) 0
98. If ( f(x) = |x| ), find ( f'(0) ).
- A) 1
- B) -1
- C) 0
- D) Undefined
99. Determine the convergence of the series ( \sum_{n=1}^{\infty} \frac{3^n}{n!} ).
- A) Converges
- B) Diverges
- C) Conditionally converges
- D) Does not converge
100. What is the inverse function of ( f(x) = \sqrt{2x + 3} )?
- A) ( f^{-1}(x) = \frac{x^2 + 3}{2} )
- B) ( f^{-1}(x) = \frac{x^2 - 3}{2} )
- C) ( f^{-1}(x) = 2x + 3 )
- D) ( f^{-1}(x) = \frac{3 - x^2}{2} )
Python Script to Split Questions into 10 Documents
To split the above 100 questions into 10 separate documents with 10 questions each, follow the steps below. This script assumes that all questions are stored in a single text file named questions.txt.
-
Prepare the Questions File:
- Save all 100 questions in a file named
questions.txt.
- Ensure that each question starts with its number followed by a period (e.g.,
1., 2., ..., 100.).
-
Python Script:
import os
def split_questions(input_file, output_dir, questions_per_file=10):
# Create output directory if it doesn't exist
if not os.path.exists(output_dir):
os.makedirs(output_dir)
with open(input_file, 'r', encoding='utf-8') as f:
content = f.read()
# Split the content into individual questions
questions = content.split('\n\n') # Assuming each question is separated by two newlines
total_questions = len(questions)
num_files = total_questions // questions_per_file
if total_questions % questions_per_file != 0:
num_files += 1 # Add an extra file for remaining questions
for i in range(num_files):
start_index = i * questions_per_file
end_index = start_index + questions_per_file
chunk = questions[start_index:end_index]
# Prepare the content for the current file
file_content = '\n\n'.join(chunk)
# Define the output file name
output_file = os.path.join(output_dir, f'questions_group_{i+1}.txt')
# Write the chunk to the output file
with open(output_file, 'w', encoding='utf-8') as out_f:
out_f.write(file_content)
print(f'Created {output_file} with questions {start_index +1} to {min(end_index, total_questions)}')
# Usage
input_filename = 'questions.txt'
output_directory = 'question_groups'
split_questions(input_filename, output_directory)
-
How the Script Works:
- Import Modules: The script uses the
os module to handle file paths and directories.
- Function
split_questions:
- Parameters:
input_file: The path to the questions.txt file containing all 100 questions.
output_dir: The directory where the split files will be saved.
questions_per_file: Number of questions per split file (default is 10).
- Process:
- Reads the entire content of
questions.txt.
- Splits the content into individual questions based on two newline characters (
\n\n), assuming that each question is separated by two newlines.
- Calculates the number of required files.
- Iterates through the questions, creating chunks of 10 questions each.
- Writes each chunk to a separate text file named
questions_group_1.txt, questions_group_2.txt, ..., questions_group_10.txt inside the specified output_dir.
- Prints a confirmation message after creating each file.
-
Running the Script:
-
Notes:
- Formatting: Make sure that each question in
questions.txt is clearly separated, preferably by two newline characters, to ensure accurate splitting.
- Customization: You can change the
questions_per_file parameter if you wish to have a different number of questions per file.
- Error Handling: This basic script does not include extensive error handling. For production use, consider adding checks for file existence, correct formatting, etc.
Feel free to modify the script according to your specific needs, such as changing the output format (e.g., PDF, Word) or the naming convention of the output files.