Skip to content

Commit 4589a97

Browse files
committedSep 17, 2021
add quiz app, database and README
1 parent c1b50ab commit 4589a97

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
 

‎QuickQuizQuestions/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ✨ Welcome to the Quick Quiz App!
2+
3+
## 📖 Description
4+
This app generates quiz questions, along with options and, of course, the correct answer!
5+
The supplied Question is picked randomly from a bank of questions and the option order is shuffled each time.
6+
Enter the option ID (A, B, C, or D) ans the application will tell you if you got it right or wrong!
7+
8+
## 🔌 Usage
9+
10+
### 📍 Installation
11+
No prior installation is required, however, you must have python 3 or higher installed on your PC.
12+
13+
### 📍 Running
14+
Navigate to the QuickQuizQuestions directory and run it using `python test.py`

‎QuickQuizQuestions/db.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"questions": [
3+
{
4+
"text":"What is the capital of India?",
5+
"options":["New Delhi", "Mumbai", "Kolkata", "Ahmedabad"],
6+
"correct":"New Delhi"
7+
},
8+
{
9+
"text":"What is the capital of Italy?",
10+
"options":["Rome", "Venice", "Ravenna", "Brundisium"],
11+
"correct":"Rome"
12+
},
13+
{
14+
"text":"What is the capital of the US?",
15+
"options":["Washington D.C.", "New York", "Florida", "Detroit"],
16+
"correct":"Washington D.C."
17+
},
18+
{
19+
"text":"What is the answer to life, the universe and everything?",
20+
"options":["42", "Love", "The Void", "Skyrim"],
21+
"correct":"42"
22+
},
23+
{
24+
"text":"Whick of the following is NOT a programming language?",
25+
"options":["Pen", "D", "Rust", "C--"],
26+
"correct":"Pen"
27+
},
28+
{
29+
"text":"Who was the inventor of dynamite?",
30+
"options":["Alfred Nobel", "Sir Hiram Maxim", "Josiah Willard Gibbs", "John Dalton"],
31+
"correct":"Alfred Nobel"
32+
},
33+
{
34+
"text":"What title did Julius Caesar NEVER officialy hold?",
35+
"options":["Consul", "Emperor", "Dictator", "Greatest Priest"],
36+
"correct":"Emperor"
37+
}
38+
39+
]
40+
}

‎QuickQuizQuestions/quiz.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import json
2+
import random
3+
f = open("db.json")
4+
db = json.load(f)
5+
question = random.choice(db['questions'])
6+
print("Q. "+question['text'])
7+
options = question['options']
8+
random.shuffle(options)
9+
c=65
10+
for option in options:
11+
print(chr(c)+") "+option)
12+
c+=1
13+
ans = input().upper()
14+
if options[ord(ans)-65] == question['correct']:
15+
print("Correct!")
16+
else:
17+
print("Wrong!")
18+
f.close()

0 commit comments

Comments
 (0)
Please sign in to comment.