Question

Using C# Create an instance of the “TestQuestion” class in your “main” method. Allow the user...

Using C#

Create an instance of the “TestQuestion” class in your “main” method. Allow the user to enter the test question and its answer, if they want to. If they do not, then continue by creating a default question and answer. Please use the constructor methods here. Then, using the “ToString” or “__str__” method, have it print out those variables as described above.

Lastly, call the “CheckAnswer” method and allow the user to continue attempting to answer the question until they are correct. If they are correct, the method should work as above and allow them to enter a new question and answer. You may either terminate the program at this point (if the user types “quit”) or allow for an infinite series of trivia games.

Example:

Please enter a test question (or just hit enter to skip): “What is your favorite color?”

Please enter the answer to that question (or just hit enter to skip): “Blue”

Your question was: “What is your favorite color?” and your answer was: “Blue”

Please enter your answer to the test question: “Red”

I’m sorry, you were incorrect and have not dethroned the previous champion. Please enter another answer to the test question: “Blue”

You are the new champion. Claim your prize by setting a new more difficult question: “What is the airspeed velocity of an unladen Swallow?”

And the answer to that question: “24 miles per hour.”

Your question was: “What is the airspeed velocity of an unladen Swallow?” and your answer was: “24 miles per hour.”

…. (It should continue asking for the correct answer. Otherwise it should end here if the user types “quit”.)

Example using Default Question and Answer:

Please enter a test question (or just hit enter to skip): “”

Please enter the answer to that question (or just hit enter to skip): “”

Your question was: “Find the value of x in 4 = x ^ 2” and your answer was: “2”

Please enter your answer to the test question: “16”

I’m sorry, you were incorrect and have not dethroned the previous champion. Please enter another answer to the test question: “4”

You are the new champion. Claim your prize by setting a new more difficult question: “What is the airspeed velocity of an unladen Swallow?”

Please enter the answer to that question: “24 miles per hour.”

Your question was: “What is the airspeed velocity of an unladen Swallow?” and your answer was: “24 miles per hour.”

…. (It should continue on like that, if using a loop. Otherwise it should end here.)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In the question it was asked to write a program representing a test question and answers also given some requirements to know the details about the program.

So below we have written the python program:

class TestQuestion:
""" TestQuestion class """
def __init__(self, quest="Find the value of x in 4 = x ^ 2", ans="2"):
""" Constructor """
self.question = quest
self.answer = ans
  
def getQuestion(self):
""" Returns question """
return self.question
  
def getAnswer(self):
""" Returns answer """
return self.answer
  
def CheckAnswer(userAns, tObj):
""" Checks answer """
while True:
if userAns==tObj.getAnswer():
return
else:
userAns = input("I'm sorry, you were incorrect and have not dethroned the previous champion. Please enter another answer to the test question: ")
  
def main():
""" Main method """
  
# Reading input from user
questC = input("Please enter a test question (or just hit enter to skip): ")
  
while True:
ansC = input("Please enter the answer to that question (or just hit enter to skip): ")
  
# Checking quest and ans
if questC=="" and ansC=="":
tObj = TestQuestion()
elif questC=="" and ansC!="":
tObj = TestQuestion(ans=ansC)
elif questC!="" and ansC=="":
tObj = TestQuestion(quest=questC)
else:
tObj = TestQuestion(questC, ansC)
  
print("Your question was: \"" + tObj.getQuestion() + "\" and your answer was: \"" + tObj.getAnswer() + "\"")
  
# Reading answer
userAns = input("Please enter your answer to the test question: ")
  
# Checking Answer
CheckAnswer(userAns, tObj)
  
# Reading input from user
questC = input("You are the new champion. Claim your prize by setting a new more difficult question (Enter quit to exit): ")
  
if questC.lower() == "quit":
return
  
  
# Calling main function
main()
  

___________________________________________________________________________________________________

Sample Run:

Here we can have a clear view of the screen.

Hence we have cleared all the given requirements in the question for the python program.

Add a comment
Know the answer?
Add Answer to:
Using C# Create an instance of the “TestQuestion” class in your “main” method. Allow the user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Urgent must be done in C# create an instance of the “ testquestion” class in your main method. al...

    Urgent must be done in C# create an instance of the “ testquestion” class in your main method. allow the uswr to enter the teat question and its answer, it they want to. if they do not, then continue by creating a default queatuon and answer. please use the constructor methods here. Then, using the “tostring or _str_method, have it print out those variables as decribed above. call the “check answer” method and allow the user to continue attempting to...

  • IN JAVA Create the “MathTest” class. It will have two class variables: 1) a question and...

    IN JAVA Create the “MathTest” class. It will have two class variables: 1) a question and 2) the answer to that question. Please create an accessor and mutator method for both of those variables, without which we would not be able to see or change the question or the answer. There should be a constructor method. We will also have a “ToString” method, which will print the question followed by its answer. The constructor method has two parameters to allow...

  • Create a program in Python that will allow the user to enter a temperature in Fahrenheit...

    Create a program in Python that will allow the user to enter a temperature in Fahrenheit which will then be converted to degrees Celsius. The program will keep asking the user for a Fahrenheit temperature until the user enters Q to quit. After each conversion the program needs to print out the degrees Celsius. The input prompts for this problem need to look like the following: Degrees Fahrenheit: Continue: For these input prompts watch the capitalization and spacing. There are...

  • Using C# Create a “Main” method that will take user input one line at a time...

    Using C# Create a “Main” method that will take user input one line at a time until they enter the phrase “done”. Store each line entered into an ArrayList, so that one element of the ArrayList is one line of user input. You do NOT need to write your own ArrayList class, please use the standard library implementation of an ArrayList. After the user finishes typing in input, ask the user for a location and file name. Save the contents...

  • Write a C++ program to allow the user to create a test bank of questions. The...

    Write a C++ program to allow the user to create a test bank of questions. The program should first ask the user how many questions he or she wishes to create. This quantity will be the first line in the test bank. The user should now be prompted for all information for each question, and then that question is written out to the test bank in the exact format specified in the Phase 2 Individual Project. For each question, the...

  • Need help with code in C# Create an application that reads a file named Accounts.txt. Your application should load the file and display back the results. The application should allow the user to enter...

    Need help with code in C# Create an application that reads a file named Accounts.txt. Your application should load the file and display back the results. The application should allow the user to enter additional entries and save them back to the same file. The CSV file should contain the following fields: AccountName, InvoiceDate, DueDate, AmountDue If the CSV file contains invalid data you want to inform the user which row contained bad data. Below is an example of what...

  • import java.util.Scanner; public class MPGMain {    public static void main(String[] args)    {       ...

    import java.util.Scanner; public class MPGMain {    public static void main(String[] args)    {        Scanner input = new Scanner(System.in);               Mileage mileage = new Mileage();               System.out.println("Enter your miles: ");        mileage.setMiles(input.nextDouble());               System.out.println("Enter your gallons: ");        mileage.setGallons(input.nextDouble());               System.out.printf("MPG : %.2f",mileage.getMPG());           } } public class Mileage {    private double miles;    private double gallons;    public double getMiles()...

  • Design an application with a single class and two static methods: method main and method isLeap....

    Design an application with a single class and two static methods: method main and method isLeap. Static method isLeap accepts year as integer and returns boolean value true or false depending whether year is leap or not. public static boolean isLeap ( int year ) The year is leap year if it is divisible by 4, but not divisible by 100 , except if it is divisible by 400. Examples 2003 is not a leap year 2020 is leap year...

  • Exercise #3: Create the “MathTest” class. It will have two class variables: 1) a question and...

    Exercise #3: Create the “MathTest” class. It will have two class variables: 1) a question and 2) the answer to that question. Exercise #4: Please create an accessor and mutator method for both of those variables, without which we would not be able to see or change the question or the answer. Exercise #5: There should be a constructor method. We will also have a “ToString” method, which will print the question followed by its answer. The constructor method has...

  • PLEASE I NEED C# Objectives Learn the basics of exception handling. Background Exceptions are essentially unexpected...

    PLEASE I NEED C# Objectives Learn the basics of exception handling. Background Exceptions are essentially unexpected situations. It is difficult to write a program that can handle all possible situations, as we have found out through the many programs we have written. For example, should your program accept accidental input? Does it use the metric system or the empirical system? Do users of your program know which system it uses? In order to deal with all these possibilities, exceptions were...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT