File tree Expand file tree Collapse file tree 3 files changed +136
-0
lines changed
Expand file tree Collapse file tree 3 files changed +136
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "questions" : [
3+ {
4+ "question" : " Who was the Lord of Winterfell in the show beginning?" ,
5+ "options" : [
6+ " Jon Snow" ,
7+ " Benjen Stark" ,
8+ " Ned Stark" ,
9+ " Robb Stark"
10+ ],
11+ "answer" : 3
12+ },
13+ {
14+ "question" : " Which house is the most powerful in Westeros south?" ,
15+ "options" : [
16+ " Lannisters" ,
17+ " Tyrells" ,
18+ " Martell" ,
19+ " Targaryens"
20+ ],
21+ "answer" : 1
22+ },
23+ {
24+ "question" : " Who stabbed the Mad king?" ,
25+ "options" : [
26+ " Robert Baratheon" ,
27+ " Ned Stark" ,
28+ " Jaime Lannister" ,
29+ " Jon Arryn"
30+ ],
31+ "answer" : 3
32+ },
33+ {
34+ "question" : " Under whose command the Lannisters won the Battle of Blackwater" ,
35+ "options" : [
36+ " Joffrey Baratheon" ,
37+ " The Hound" ,
38+ " Tyrion Lannister" ,
39+ " Cersei Lannister"
40+ ],
41+ "answer" : 3
42+ },
43+ {
44+ "question" : " Who did Arya Stark meet in Bravos?" ,
45+ "options" : [
46+ " Jon Snow" ,
47+ " Jacqen H'hgar" ,
48+ " Brienne of Tarth" ,
49+ " Daenerys Targaryen"
50+ ],
51+ "answer" : 2
52+ },
53+ {
54+ "question" : " What house did Ser Jorah belong to?" ,
55+ "options" : [
56+ " Targaryen" ,
57+ " Freys" ,
58+ " Boltons" ,
59+ " Mormonts"
60+ ],
61+ "answer" : 4
62+ },
63+ {
64+ "question" : " How did Robb Stark die?" ,
65+ "options" : [
66+ " Got killed in the War of the five kings" ,
67+ " Stabbed by his own mother Catelyn" ,
68+ " Killed in the Red Wedding" ,
69+ " Killed by his horse"
70+ ],
71+ "answer" : 3
72+ },
73+ {
74+ "question" : " Who was the daughter of Stannis?" ,
75+ "options" : [
76+ " Princess Shireen" ,
77+ " Princess Lyanna" ,
78+ " Princess Arya" ,
79+ " Princess Myrcella"
80+ ],
81+ "answer" : 1
82+ }
83+ ]
84+ }
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+
3+ import json
4+ import random
5+
6+ def get_questions ():
7+ questions_file = open ('/home/shrav/Desktop/workspace/pythoooonnn/got_quiz/quiz.json' )
8+ questions_obj = json .load (questions_file )
9+ questions_file .close ()
10+ return questions_obj ['questions' ]
11+
12+ def print_choices (choices ):
13+ for index , choice in enumerate (choices ):
14+ print ('{}.{}' .format (index + 1 , choice ), '\n ' )
15+
16+ def is_correct (ans , user_answer ):
17+ return ans == str (user_answer )
18+
19+ def start_quiz ():
20+ questions = get_questions ()
21+ points = 0
22+ for index , val in enumerate (questions ):
23+ print (val ['question' ], '\n ' ) # Question
24+ print_choices (val ['options' ])
25+ answer = input ('Your answer(in number)?\n ' )
26+ if is_correct (answer , val ['answer' ]):
27+ print ('✓' )
28+ points += 1
29+ else :
30+ print ('✘' )
31+ print ('You got {}/{} questions correct. Hooray' .format (points , len (questions )))
32+
33+
34+ if __name__ == "__main__" :
35+ canPlay = input ('Press y/Y to play the Game of Thrones quiz 🦁\n ' )
36+ canPlay = str (canPlay ) == 'y' or str (canPlay ) == 'Y'
37+ start_quiz () if canPlay else exit (- 1 )
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ def is_prime_number (num ):
3+ i = 2
4+ isPrime = True
5+ while i <= (num // 2 ):
6+ if num % i == 0 :
7+ isPrime = False
8+ break
9+ i += 1
10+ return isPrime
11+
12+ number = int (input ('Enter number \n ' ))
13+ isPrime = is_prime_number (number )
14+
15+ print ('{} is {}' .format (number , 'prime' if isPrime else 'composite' ))
You can’t perform that action at this time.
0 commit comments