quiz program
python_questions_answers = {
"What is the full form of API?": "Application Programming Interface",
"When was Python created?": "1989",
"Who is the creator of Python?": "Guido van Rossum",
"What is the syntax used to create functions in Python?": "def function_name():",
"What is the latest stable version of Python?": "Python 3.10",
"What are the two main loop constructs in Python?": "for loop and while loop",
"What is the purpose of the 'pass' statement in Python?": "It is a null operation and does nothing. It is used as a placeholder.",
"What is the difference between '==' and 'is' in Python?": "'==' compares the values of two objects, while 'is' compares their identities (memory addresses).",
"What is a module in Python?": "A file containing Python code, which can be imported and used in other Python files.",
"How do you comment out multiple lines in Python?": "You can use triple quotes (''' or \"\"\") to comment out multiple lines.",
"What is the purpose of the 'import' keyword in Python?": "It is used to import modules or specific objects from modules into the current namespace.",
"What is a tuple in Python?": "An immutable collection of ordered elements, similar to a list but cannot be modified after creation.",
"What is the 'self' keyword used for in Python?": "It is a reference to the current instance of the class and is used to access variables and methods within the class.",
"What is a list comprehension in Python?": "A concise way to create lists in Python using a single line of code.",
"What is the purpose of the 'enumerate()' function in Python?": "It adds a counter to an iterable and returns it as an enumerate object.",
"What is a generator in Python?": "A function that returns an iterator and generates values lazily, one at a time, rather than all at once.",
"What is the difference between 'append()' and 'extend()' methods in Python lists?": "'append()' adds an element to the end of the list, while 'extend()' adds the elements of an iterable (e.g., another list) to the end of the list.",
"What is the purpose of the 'with' statement in Python?": "It is used to simplify exception handling and resource management by ensuring that certain operations are always performed before leaving a block of code.",
"What is the difference between 'TypeError' and 'NameError' in Python?": "'TypeError' occurs when an operation or function is applied to an object of inappropriate type, while 'NameError' occurs when a local or global name is not found.",
"What is the purpose of the 'global' keyword in Python?": "It is used to declare that a variable inside a function is global (i.e., it can be accessed and modified outside the function).",
"What is the purpose of the '__init__()' method in Python classes?": "It is a constructor method that is automatically called when a new instance of the class is created. It is used to initialize instance variables.",
"What is the difference between 'instance variables' and 'class variables' in Python?": "Instance variables are unique to each instance of a class, while class variables are shared among all instances of the class.",
"What is a decorator in Python?": "A function that modifies the behavior of another function or method.",
"What is the purpose of the 'super()' function in Python?": "It is used to call methods of a superclass from a subclass.",
"What is the purpose of the '__name__' variable in Python?": "It is a special variable that holds the name of the current module. When a module is run as the main program, its '__name__' variable is set to '__main__'."
}
Q = 25
def q(questions,num_questions):
score = []
start_program = input("do you want to start the program y/n ? ")
if start_program == 'y':
print("lets start the program")
for question, python_questions_answers in questions.items():
user_input = input(question)
if user_input == 'q':
quit()
correct_answer = questions[question]
if user_input == correct_answer:
score.append(correct_answer)
current_score = len(score)
print(f"correct!, your current score is {current_score}")
else:
print(f"incorrect! the correct answer is: {correct_answer}")
total_score = len(score)
print(f" your total score is {total_score}")
(q(python_questions_answers,Q))
Comments
Post a Comment