
![]() |
@wtf | |
(Quiz app using OOP concepts) |
||
1
Replies
9
Views
1 Bookmarks
|
![]() |
@wtf | 7 days |
*OOP Review + Quiz App Project* We'll build a console-based quiz app using: - Classes & Objects - Attributes & Methods - Input handling - Simple logic to track scores *Step 1: Create a Question Class* class Question: def __init__(self, prompt, answer): self.prompt = prompt self.answer = answer Each object of this class will represent one quiz question. *Step 2: Define the Questions* questions = [ Question(What is the capital of India?n(a) Delhin(b) Mumbain(c) Kolkatan, a), Question(Which language is known as the language of the web?n(a) Pythonn(b) JavaScriptn(c) C++n, b), Question(What does OOP stand for?n(a) Object Oriented Programmingn(b) Original Open Platformn(c) Other Output Packagen, a) ] *Step 3: Create the Quiz Logic* def run_quiz(questions): score = 0 for q in questions: answer = input(q.prompt) if answer.lower() == q.answer: score += 1 print(fYou got score/len(questions) correct!) *Step 4: Run the App* run_quiz(questions) *What You Practiced:* - Creating custom classes - Managing collections of objects - User input handling - Conditional logic - Tracking and displaying scores *Optional Enhancements (Try these later):* - Shuffle the questions - Add difficulty levels - Track high scores - Timer for each question - Save results to a file |
||


