diff --git a/.gitignore b/.gitignore index c37dbbd..ab13f3c 100644 --- a/.gitignore +++ b/.gitignore @@ -94,7 +94,6 @@ venv/ ENV/ env.bak/ venv.bak/ -data/ # Spyder project settings .spyderproject .spyproject diff --git a/cogs/codebuddy_quiz.py b/cogs/codebuddy_quiz.py index 9904613..2cf578e 100644 --- a/cogs/codebuddy_quiz.py +++ b/cogs/codebuddy_quiz.py @@ -65,8 +65,8 @@ async def post_question_loop(self): return options_letters = ["a", "b", "c"] - options_text = [f"{options_letters[idx]}) {q['options'][idx]}" for idx in range(len(options_letters))] - options_text = "\n".join(options_text) + options_text = "\n".join(f"**{letter})** {option}" for letter, option in zip(options_letters, q["options"])) + embed = discord.Embed( title="❓ Coding Quiz", description=f"**{self.current_question}**\n\n{options_text}", diff --git a/data/coding_questions.json b/data/coding_questions.json new file mode 100644 index 0000000..684e12e --- /dev/null +++ b/data/coding_questions.json @@ -0,0 +1,1309 @@ +[ + { + "language": "Python", + "question": "What is the output of this code?\n```python\nprint(type(lambda: None))\n```", + "options": ["", "", ""], + "correct": "a", + "explanation": "Lambdas are functions in Python." + }, + { + "language": "Python", + "question": "Which of these is NOT a valid way to create a set?", + "options": ["{1, 2}", "set([1, 2])", "{}"], + "correct": "c", + "explanation": "`{}` creates an empty dictionary, not a set. Use `set()` for an empty set." + }, + { + "language": "Python", + "question": "What is the output?\n```python\na = [1, 2, 3]\nb = a\na += [4]\nprint(b)\n```", + "options": ["[1, 2, 3]", "[1, 2, 3, 4]", "Error"], + "correct": "b", + "explanation": "`+=` on lists modifies the list in-place, so `b` (which references the same object) sees the change." + }, + { + "language": "Python", + "question": "What does the `__init__` method do?", + "options": [ + "Initializes a class", + "Initializes an object (instance)", + "Creates a new module" + ], + "correct": "b" + }, + { + "language": "Python", + "question": "What is the result of `print(0.1 + 0.2 == 0.3)`?", + "options": ["True", "False", "Error"], + "correct": "b", + "explanation": "Floating point precision issues make 0.1 + 0.2 slightly larger than 0.3." + }, + { + "language": "Python", + "question": "Which decorator is used to define a class method?", + "options": ["@static", "@classmethod", "@method"], + "correct": "b" + }, + { + "language": "Python", + "question": "What is the output of `print('a' < 'b')`?", + "options": ["True", "False", "Error"], + "correct": "a", + "explanation": "Strings are compared lexicographically (ASCII value)." + }, + { + "language": "Python", + "question": "What keyword is used to handle exceptions?", + "options": ["catch", "except", "handle"], + "correct": "b" + }, + { + "language": "Python", + "question": "What is a generator in Python?", + "options": [ + "A function that returns a list", + "A function that yields values one by one", + "A tool to generate code" + ], + "correct": "b" + }, + { + "language": "Python", + "question": "What is the output?\n```python\nx = (1)\nprint(type(x))\n```", + "options": ["", "", ""], + "correct": "b", + "explanation": "A single element tuple requires a comma: `(1,)`." + }, + { + "language": "JavaScript", + "question": "What is the output of `console.log(typeof NaN)`?", + "options": ["'number'", "'NaN'", "'undefined'"], + "correct": "a", + "explanation": "NaN stands for Not-a-Number, but its type is technically 'number'." + }, + { + "language": "JavaScript", + "question": "What is the result of `[] + []`?", + "options": ["[]", "'' (Empty String)", "0"], + "correct": "b", + "explanation": "Arrays are converted to strings and concatenated." + }, + { + "language": "JavaScript", + "question": "Which keyword declares a block-scoped variable?", + "options": ["var", "let", "def"], + "correct": "b" + }, + { + "language": "JavaScript", + "question": "What is the output of `console.log(0.1 + 0.2 === 0.3)`?", + "options": ["true", "false", "undefined"], + "correct": "b", + "explanation": "Floating point arithmetic." + }, + { + "language": "JavaScript", + "question": "How do you create a Promise?", + "options": [ + "new Promise((resolve, reject) => ...)", + "Promise.create()", + "async function()" + ], + "correct": "a" + }, + { + "language": "JavaScript", + "question": "What does `===` check?", + "options": ["Value only", "Value and Type", "Reference"], + "correct": "b" + }, + { + "language": "JavaScript", + "question": "What is the output?\n```javascript\nconsole.log('5' - 3)\n```", + "options": ["2", "'53'", "NaN"], + "correct": "a", + "explanation": "The `-` operator converts the string to a number." + }, + { + "language": "JavaScript", + "question": "What is a closure?", + "options": [ + "A function bundled with its lexical environment", + "The end of a function", + "A closed class" + ], + "correct": "a" + }, + { + "language": "JavaScript", + "question": "Which method removes the last element from an array?", + "options": ["shift()", "pop()", "remove()"], + "correct": "b" + }, + { + "language": "JavaScript", + "question": "What is the output?\n```javascript\nconsole.log(1 + '1')\n```", + "options": ["2", "'11'", "NaN"], + "correct": "b", + "explanation": "The `+` operator with a string performs concatenation." + }, + { + "language": "Java", + "question": "What is the size of an `int` in Java?", + "options": ["16 bit", "32 bit", "64 bit"], + "correct": "b" + }, + { + "language": "Java", + "question": "Which keyword is used to inherit a class?", + "options": ["implements", "extends", "inherits"], + "correct": "b" + }, + { + "language": "Java", + "question": "What is the default value of a boolean variable?", + "options": ["true", "false", "null"], + "correct": "b" + }, + { + "language": "Java", + "question": "Which collection allows duplicate elements?", + "options": ["Set", "List", "Map (Keys)"], + "correct": "b" + }, + { + "language": "Java", + "question": "What is the entry point of a Java program?", + "options": [ + "public static void main(String[] args)", + "void main()", + "public void start()" + ], + "correct": "a" + }, + { + "language": "Java", + "question": "Is Java pass-by-reference or pass-by-value?", + "options": ["Pass-by-reference", "Pass-by-value", "Both"], + "correct": "b", + "explanation": "Java is strictly pass-by-value. Object references are passed by value." + }, + { + "language": "Java", + "question": "Which keyword makes a variable constant?", + "options": ["const", "final", "static"], + "correct": "b" + }, + { + "language": "Java", + "question": "What is the parent class of all classes in Java?", + "options": ["Class", "Object", "Main"], + "correct": "b" + }, + { + "language": "Java", + "question": "How do you compare two strings for equality?", + "options": ["==", ".equals()", ".compare()"], + "correct": "b", + "explanation": "`==` compares references, `.equals()` compares content." + }, + { + "language": "Java", + "question": "What is an interface?", + "options": [ + "A class with only abstract methods (mostly)", + "A concrete class", + "A variable type" + ], + "correct": "a" + }, + { + "language": "C++", + "question": "What is the output?\n```cpp\nint x = 5;\ncout << x++ << ++x;\n```", + "options": ["57", "66", "Undefined Behavior"], + "correct": "c", + "explanation": "The order of evaluation of operands in `<<` is unspecified/undefined in older standards (before C++17)." + }, + { + "language": "C++", + "question": "Which operator is used to access members of a pointer?", + "options": [".", "->", "::"], + "correct": "b" + }, + { + "language": "C++", + "question": "What is a destructor?", + "options": [ + "A method to delete a class", + "A method called when an object is destroyed", + "A method to free memory manually" + ], + "correct": "b" + }, + { + "language": "C++", + "question": "What is the difference between `struct` and `class`?", + "options": [ + "No difference", + "Default access specifier", + "Structs cannot have methods" + ], + "correct": "b", + "explanation": "Struct members are public by default; class members are private." + }, + { + "language": "C++", + "question": "What does `virtual` keyword do?", + "options": [ + "Enables polymorphism", + "Makes a function faster", + "Creates a virtual machine" + ], + "correct": "a" + }, + { + "language": "C++", + "question": "How do you allocate memory dynamically?", + "options": ["malloc", "new", "Both"], + "correct": "c" + }, + { + "language": "C++", + "question": "What is a reference?", + "options": [ + "A pointer", + "An alias for an existing variable", + "A copy of a variable" + ], + "correct": "b" + }, + { + "language": "C++", + "question": "What is the STL?", + "options": [ + "Standard Template Library", + "Standard Type List", + "Simple Text Language" + ], + "correct": "a" + }, + { + "language": "C++", + "question": "What is `std::vector`?", + "options": ["A static array", "A dynamic array", "A linked list"], + "correct": "b" + }, + { + "language": "C++", + "question": "What is the size of an empty class?", + "options": ["0 bytes", "1 byte", "4 bytes"], + "correct": "b", + "explanation": "To ensure that two different objects have different addresses." + }, + { + "language": "C#", + "question": "Which keyword is used for inheritance?", + "options": ["extends", ":", "implements"], + "correct": "b" + }, + { + "language": "C#", + "question": "What is LINQ?", + "options": [ + "Language Integrated Query", + "Linked Integer Queue", + "List Index Query" + ], + "correct": "a" + }, + { + "language": "C#", + "question": "What is the base class for all types in C#?", + "options": ["System.Object", "System.Base", "System.Root"], + "correct": "a" + }, + { + "language": "C#", + "question": "Which keyword is used to define an asynchronous method?", + "options": ["await", "async", "thread"], + "correct": "b" + }, + { + "language": "C#", + "question": "What is a nullable type?", + "options": ["int?", "int!", "null"], + "correct": "a" + }, + { + "language": "C#", + "question": "What is the difference between `ref` and `out`?", + "options": [ + "`out` requires initialization before passing", + "`ref` requires initialization before passing", + "No difference" + ], + "correct": "b" + }, + { + "language": "C#", + "question": "What is a property?", + "options": [ + "A variable", + "A member that provides a flexible mechanism to read, write, or compute the value of a private field", + "A method" + ], + "correct": "b" + }, + { + "language": "C#", + "question": "What does `using` statement do?", + "options": [ + "Imports a namespace", + "Ensures IDisposable objects are disposed", + "Both" + ], + "correct": "c" + }, + { + "language": "Rust", + "question": "What is the ownership model?", + "options": [ + "A way to manage memory without a garbage collector", + "A way to buy code", + "A licensing model" + ], + "correct": "a" + }, + { + "language": "Rust", + "question": "Which keyword defines a mutable variable?", + "options": ["var", "let mut", "mut"], + "correct": "b" + }, + { + "language": "Rust", + "question": "What is `Option`?", + "options": [ + "A type that represents an optional value (Some or None)", + "A configuration option", + "A compiler flag" + ], + "correct": "a" + }, + { + "language": "Rust", + "question": "What is the output of `println!(\"{}\", 5)`?", + "options": ["5", "{5}", "Error"], + "correct": "a" + }, + { + "language": "Rust", + "question": "What is a `Result` type used for?", + "options": ["Returning values", "Error handling", "Math calculations"], + "correct": "b" + }, + { + "language": "Rust", + "question": "What does `unwrap()` do?", + "options": [ + "Extracts the value from Option/Result or panics", + "Opens a file", + "Decrypts data" + ], + "correct": "a" + }, + { + "language": "Rust", + "question": "What is a trait?", + "options": [ + "A class", + "A collection of methods that can be implemented by types", + "A variable type" + ], + "correct": "b" + }, + { + "language": "Rust", + "question": "How do you create a new vector?", + "options": ["Vector.new()", "vec![]", "list[]"], + "correct": "b" + }, + { + "language": "Rust", + "question": "What is the borrow checker?", + "options": [ + "A library", + "A compiler part that enforces ownership rules", + "A linter" + ], + "correct": "b" + }, + { + "language": "Rust", + "question": "What is `match`?", + "options": [ + "A regex tool", + "A control flow operator for pattern matching", + "A game" + ], + "correct": "b" + }, + { + "language": "Web Dev", + "question": "What does HTML stand for?", + "options": [ + "Hyper Text Markup Language", + "High Tech Modern Language", + "Hyperlinks and Text Markup Language" + ], + "correct": "a" + }, + { + "language": "Web Dev", + "question": "Which tag is used for the largest heading?", + "options": ["", "
", "

"], + "correct": "c" + }, + { + "language": "Web Dev", + "question": "What does CSS stand for?", + "options": [ + "Computer Style Sheets", + "Cascading Style Sheets", + "Creative Style Sheets" + ], + "correct": "b" + }, + { + "language": "Web Dev", + "question": "Which property changes text color?", + "options": ["text-color", "color", "font-color"], + "correct": "b" + }, + { + "language": "Web Dev", + "question": "What is the Box Model?", + "options": [ + "A layout concept (Content, Padding, Border, Margin)", + "A 3D model", + "A flexbox container" + ], + "correct": "a" + }, + { + "language": "Web Dev", + "question": "Which unit is relative to the font-size of the root element?", + "options": ["em", "rem", "px"], + "correct": "b" + }, + { + "language": "Web Dev", + "question": "What is Flexbox?", + "options": [ + "A layout module for one-dimensional layouts", + "A grid system", + "A JavaScript library" + ], + "correct": "a" + }, + { + "language": "Web Dev", + "question": "Which tag is used to link a JavaScript file?", + "options": ["", "