PromptBase
Close icon
Explore
General
Home
Marketplace
Apps
Create
Login
Sell
🤖 GPT

Python Quiz Generator

Python Quiz Generator gpt prompt mini thumbnail
1Heart icon
Favorites
155Eye icon
Views
TestedTick icon
TipsTick icon
generate a quiz in python about anything.
...more
$3.99
Get prompt
After purchasing, you will gain access to the prompt file which you can use with GPT or the app builder. You'll receive 20 free generation credits with this purchase. By purchasing this prompt, you agree to our terms of service.
Over 1 month ago

Prompt Details

Model
Chat - GPT-3.5 (gpt-3.5-turbo)
Token size
113 ($0.00020 / call)
Example input
Variables: [programming language]: the programming language for which the game is developed, e.g., Python, Java, C++, JavaScript, Ruby, etc. [programming language concept]: the main topic or concept of the programming language that the game will focus on, e.g., syntax, data types, control structures, functions, modules, OOP, etc. [subtopics]: specific subtopics or areas within the main topic that the game will cover, e.g., conditionals, loops, lists, strings, variables, classes, methods, inheritance, polymorphism, etc.
Example output
Here is a Python game that quizzes users on PCAP certification topics: python Copy code import random # Define the quiz questions and answers quiz = [ { "question": "What is the output of the following code?\n\nx = [1, 2, 3]\nprint(x[1:])", "answers": ["[2, 3]", "[1, 2]", "[1, 2, 3]", "2"], "correct_answer": "[2, 3]", "explanation": "The slice notation x[1:] returns a new list starting from index 1 to the end of the list." }, { "question": "What is the result of the following expression?\n\n2 * 3 ** 3 % 5", "answers": ["1", "3", "4", "0"], "correct_answer": "1", "explanation": "The expression evaluates as 2 * (3 ** 3) % 5, which is 2 * 27 % 5, which is 1." }, { "question": "What is the output of the following code?\n\nx = (1, 2, 3)\ny = [i ** 2 for i in x]\nprint(y)", "answers": ["[1, 4, 9]", "(1, 4, 9)", "1 4 9", "{1, 4, 9}"], "correct_answer": "[1, 4, 9]", "explanation": "The list comprehension [i ** 2 for i in x] creates a new list with the squares of each element in x." }, { "question": "What is the output of the following code?\n\ndef foo(a, b=2, c=3):\n print(a, b, c)\nfoo(1)", "answers": ["1 2 3", "1 2", "1 3", "1"], "correct_answer": "1 2 3", "explanation": "The function foo has three parameters, with b and c having default values of 2 and 3, respectively. When the function is called with only one argument, the default values are used for the other parameters." }, { "question": "What is the output of the following code?\n\nimport math\nprint(math.sqrt(16))", "answers": ["4.0", "4", "2.0", "2"], "correct_answer": "4.0", "explanation": "The math.sqrt() function returns the square root of a number. In this case, it returns 4.0." } ] # Define the function to run the quiz game def run_quiz(): random.shuffle(quiz) # Shuffle the quiz questions score = 0 for i, question in enumerate(quiz): print(f"\nQuestion {i + 1}:") print(question["question"]) for j, answer in enumerate(question["answers"]): print(f"{j + 1}. {answer}") user_answer = input("Your answer: ") if user_answer == question["correct_answer"]: print("Correct!") score += 1 else: print("Incorrect!") print(question["explanation"]) print(f"\nYou scored {score} out of {len(quiz)}!") # Run the quiz game run_quiz() In this game, the quiz questions and answers are defined in a list of dictionaries. Each dictionary
Browse Marketplace