Question

In: Computer Science

Develop a python program to ask the user to take up the quiz(General knowledge) which has...

Develop a python program to ask the user to take up the quiz(General knowledge) which has around 4 or 5 questions & choices for those questions.

For each question user should have 2 or 3 attempts suppose if they are wrong.

Develop the in such a manner to add few more questions and remove some questions.

Solutions

Expert Solution

CODE:

#this class depicts a question which has four options
#a question and a correct option
class Question():
#constructor
def __init__(self,question,optionA,optionB,optionC,optionD,correctOptionNumber):
self.question = question
self.optionA = optionA
self.optionB = optionB
self.optionC = optionC
self.optionD = optionD
#the optionNumber should be either 1,2,3 or 4
if(correctOptionNumber not in range(1,5)):
raise Excpetion("invalid option entered as correct option")
self.correctOption = correctOptionNumber
  
#str() method
def __str__(self):
return "Q. {}\n1. {}\n2. {}\n3. {}\n4. {}".format(self.question,
self.optionA,
self.optionB,
self.optionC,
self.optionD)

def main():
#list of Question objects in the list which can be added or removed
Quiz = []
#appending the question objects in the list
Quiz.append(Question("What is the capital of United States of America?",
"New York",
"Washington D.C.",
"California",
"Las Vegas",
2))
Quiz.append(Question("How many legs does a caterpillar has?",
"6",
"50",
"4",
"2",
1))
Quiz.append(Question("Who is the king of the jungle?",
"Cat",
"Dog",
"Lion",
"Cheetah",
3))
Quiz.append(Question("What is the capital of United Kingdom?",
"Germany",
"Washington D.C.",
"Paris",
"London",
4))
right = 0
wrong = 0
#all the questions in the list is asked
for i in Quiz:
attempts = 0
correctlyAnswered = False
print("\n___________________________________________")
print(i)
print("___________________________________________")
while(True):
#asking the correct option
answer = int(input("Enter the correct option Number: "))
attempts += 1
if(answer == i.correctOption):
print('\nCorrect!')
#points gained if answered correctly
correctlyAnswered = True
break
else:
print('\nWrong! {} attempts left!'.format(str(2-attempts)))
#if two wrong attempts are made points lost
if(attempts == 2):
print("\nYou couldn't answer")
break
#if that question was answered correctly points scored otherwise not
if(correctlyAnswered):
right += 1
else:
wrong += 1
#printing the score of the quiz
print("\nFinal Score:\nRight: {}\nWrong: {}".format(str(right),str(wrong)))
  
main()

_________________________________________

CODE IMAGES:

_____________________________________________

OUTPUT:

_________________________________________

Feel free to ask any questions in the comments section
Thank You!


Related Solutions

Develop a python program that prompts the user to take up the quiz (which has choices)...
Develop a python program that prompts the user to take up the quiz (which has choices) with limited attempts and limited time. Suppose if the user answered wrong then they have to get numer of attempts(limited) Quiz should have questions on General knowldge & multiple choices for those questions
Program a math quiz on Python Specifications: - The program should ask the user a question...
Program a math quiz on Python Specifications: - The program should ask the user a question and allow the student to enter the answer. If the answer is correct, a message of congratulations should be displayed. If the answer is incorrect, a message showing the correct answer should be displayed. - the program should use three functions, one function to generate addition questions, one for subtraction questions, and one for multiplication questions. - the program should store the questions and...
In python. Projectile motion: Write a python program that will ask the user for      an...
In python. Projectile motion: Write a python program that will ask the user for      an initial height y0, initial velocity v, launch angle theta, and mass m.      Create two functions, one that will calculate max height      of the projectile, and one that will calculate the range. Ask the     user which one he/she would like to calculate, then present them with the answer. (use kg, m and m/s)
Write a Python program that has a loop to continuously ask the user for a number,...
Write a Python program that has a loop to continuously ask the user for a number, terminating the loop when the number entered is -1. Inside the loop, 1.) display one asterisk(*) if the number is 1, 2.) two asterisk(**) if the number is 2 and 3.) "OTHER" if the number is any other number.
Calculating Delivery Cost Program in Python write a program in Python that will ask a user...
Calculating Delivery Cost Program in Python write a program in Python that will ask a user to enter the purchase total, the number of the items that need to be delivered and delivery day. Then the system displays the cost of delivery along with the total cost. Purchase total > $150 Yes Number of the items (N) N<=5 N>=6 Delivery day Same Day Next Day Same Day Next Day Delivery charges ($) 8 N * 1.50 N * 2.50 N...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will first enter a password, then enters the same password again; If the second input is the same as first one, the user successfully creates the password. Print “Well done.”; Otherwise, the user will be directed to repeat the whole process (go to step 1.)
Write a Python program that will ask the user to input a word, will return the...
Write a Python program that will ask the user to input a word, will return the first letter of the input word, and ask the user to put another word, and so on, in the form of a loop. If the user chooses to stop, he or she should input the integer "0" for the loop to stop.
Flowchart + Python. Ask the user for a value. Then, ask the user for the number...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number of expressions of that value. Use While Loops to make a program. So then, it should be so that 5 expressions for the value 9 would be: 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 Flowcharts and Python Code. Not just Python code. I cannot read handwriting....
Develop a python program to create a quiz with limited time and attempts!!! Add comments and...
Develop a python program to create a quiz with limited time and attempts!!! Add comments and screenshot of running the program quiz could be of anything like , what's the sum of 2&2. There should be number of attempts(limited) suppose if the answer is wrong.
PYTHON Modify the program in section Ask the user for a first name and a last...
PYTHON Modify the program in section Ask the user for a first name and a last name of several people.  Use a loop to ask for user input of each person’s first and last names  Each time through the loop, use a dictionary to store the first and last names of that person  Add that dictionary to a list to create a master list of the names  Example dictionary: aDict = { "fname":"Douglas", "name":"Lee" } ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT