Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #question.txt
- #=============
- # Q:The longest river in the world? * 1. Nile, 2. Maykha, 3. Malikha * 1
- # Q:The highest mountain in the world? * 1. Everest, 2. Fuji , 3. Kharkaborazi * 1
- # Q:The longest river in the world? * 1. Nile, 2. Maykha, 3. Malikha * 1
- # Q:The highest mountain in the world? * 1. Everest, 2. Fuji , 3. Kharkaborazi * 1
- # Q:The longest river in the world? * 1. Nile, 2. Maykha, 3. Malikha * 1
- # Q:The highest mountain in the world? * 1. Everest, 2. Fuji , 3. Kharkaborazi * 1
- # Q:The longest river in the world? * 1. Nile, 2. Maykha, 3. Malikha * 1
- # Q:The highest mountain in the world? * 1. Everest, 2. Fuji , 3. Kharkaborazi * 1
- # Q:The longest river in the world? * 1. Nile, 2. Maykha, 3. Malikha * 1
- # Q:The highest mountain in the world? * 1. Everest, 2. Fuji , 3. Kharkaborazi * 1
- # pip install icecream
- from icecream import ic #ic is used for detailed printing
- def quiz():
- marks = 0
- question = [] #empty list to store one question
- questions = [] #empty list to store all questions which concat with '*'
- #collect all questions from file question.txt
- input_file = open('question.txt','r')
- questions = input_file.readlines() # questions - List , one item contains q, options, correct ans, concat with '*'
- input_file.close()
- #print(questions)
- for q in questions:
- # q is one item of questioncontains q, options, correct ans, concat with '*'
- question = q.split('*') # question list contains [0]Q, [1]options, [2]correct ans
- correct_ans = question[2].strip() #strip is used to eliminate unwanted space or '\n' '\r' etc..
- print(question[0])
- print(question[1])
- user_ans = input('Choose correct answer: ')
- #ic(user_ans)
- #ic(correct_ans)
- if user_ans == correct_ans:
- print('Correct')
- marks += 1
- else:
- print('Wrong ans')
- print(f'Total marks = {marks}')
- if __name__ == "__main__":
- quiz()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement