Question

Python Problem: To feel good about programming, one should really develop a program that is interesting...

Python Problem:

To feel good about programming, one should really develop a program that is interesting enough to feel good about. Here are some recommended choices for a program to turn in at the end of the semester. The intent here is not to intimidate you about the course demands, but to provide a focal point for your mental energies throughout the term.

Only one project is required per student. You do not need to turn in all three.

A simple quiz

A file will consist of a series of questions and answers, something like this:

This will ask about world capitals.
What is the capital of France?,Paris
What is the capital of Egypt?,Cairo
What country has Tokyo as a capital?,Japan
What country has Lima as a capital?,Peru

The program will read the contents of the file and then create a quiz from those questions:

What is the name of the question file? capitals
This will ask for the capitals of several countries.
What is the capital of Japan? tokyo
Correct!
What is the country has Lima as a capital? Peru
Correct!
What is the capital of Assyria?  I don't know that!
Incorrect!  The answer is Nineveh

You got 2 answers correct out of 3, which is 67%

At least 10 questions should be asked out of a question bank of at least 15. Questions should be chosen at random from the collection, without repeating. Also, answers should be case-insensitive (i.e. upper or lowercase letters should be equally good).

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

****This requires some effort so please drop a like if you are satisfied with the solution****

I have satisfied all the requirements of the question and I'm providing the screenshots of code and output for your reference....

Code:

import re
import random

filename = input("What is the name of the question file? ")
if filename == "capitals":
    print("This will ask for the capitals of several countries")
f = open(filename + ".txt", "r")
content = f.read()
content = re.split("\\n|,", content)
quesAndAns = {}
i = 0
while i < len(content) - 1:
    quesAndAns[content[i]] = content[i + 1].lower()
    i += 2

questions = quesAndAns.keys()
questions = list(questions)
i = correct = wrong = 0
while i != 10:
    choice = random.randint(0, len(questions))
    answer = input(questions[choice] + " ")
    if quesAndAns[questions[choice]] == answer.lower():
        correct += 1
        print("Correct!")
    else:
        wrong += 1
        print("Incorrect, The answer is " + (quesAndAns[questions[choice]]).capitalize())
    i += 1
    questions.pop(choice)

print("\nYou got " + str(correct) + " answers out of 10, which is " + str(correct * 10)+"%")

Output Screenshot:

lule Lile TILL TILVI .VI LudlerVS/Cleyuluues/ULI YLITUI What is the name of the question file? capital This will ask for the

Code and File Screenshot:

Code.py Dimport re import random filename = input(What is the name of the question tile?) if filename == capitals: print(

Add a comment
Know the answer?
Add Answer to:
Python Problem: To feel good about programming, one should really develop a program that is interesting...
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
  • Programming Assignment Objective Write a Java program that utilizes multiple classes. Write a Java program that...

    Programming Assignment Objective Write a Java program that utilizes multiple classes. Write a Java program that utilizes inheritance in a practical manner. Problem: Quiz Bowl Your high school quiz bowl team has been losing its edge and needs to find a method to improve. Knowing that you are a savvy programmer, your coach asks you to write a program that the team members can use to hone their skills. Quiz Bowl questions come in three varieties: True/False Multiple Choice (variable...

  • Piggy back on the programming project one you completed in module 3. You will use some...

    Piggy back on the programming project one you completed in module 3. You will use some of those concepts here again. We will be building this project inside out, start individual quiz and use a for loop to repeat it three times for three students. In this program you will be required to write a python program that generates math quizzes for students in second grade. Your program should do the following Ask the student for their name Provide 3...

  • A - Write pseudocode B - Write A PYTHON PROGRAM Driver’s License Exam The local driver’s...

    A - Write pseudocode B - Write A PYTHON PROGRAM Driver’s License Exam The local driver’s license office has asked you to design a program that grades the written portion of the driver’s license exam. The exam has 20 multiple choice questions. Here are the correct answers: B D A A C A B A C D B C D A D C C B D A Your program should store these correct answers in an array. (Store each question’s...

  • Develop on knowledge based question about nutrition assessment. This can be a straight definition, or something...

    Develop on knowledge based question about nutrition assessment. This can be a straight definition, or something directly from the text. Develop a risk factor question one of your vital signs (This can include pain). A question that describes risk factors for that particular vital sign. Remember only one correct answer. Develop an assessment question asking what you should do first in the situation. All answers can be correct answers, but you're asking what should be done first (Hint: Assessment comes...

  • Describe how you would develop object-oriented features of Java for the Quiz program developed in the...

    Describe how you would develop object-oriented features of Java for the Quiz program developed in the Programming Assignments. In particular, describe how the program could use each of the following: class variables, instance variables, inheritance, polymorphism, abstract classes, "this", "super", interfaces, and event listeners. Your Discussion should be at least 250 words in length, but not more than 750 words. QUIZ PROGRAM EXAMPLE: Files "QuestionDialog.java": import java.awt.event.*; import javax.swing.*; public class QuestionDialog extends JDialog implements ActionListener { String answer; public...

  • Hello I need help with this. I am trying to use JOptionpane to ask 5 questions....

    Hello I need help with this. I am trying to use JOptionpane to ask 5 questions. However I cannot get the program to do anything after an initial selection is made. Here is the assignment. Write an application that creates a quiz, which contains at least five questions about a hobby, popular music, astronomy, or any other personal interest. Each question should be a multiple choice question with at least three options. When a user answers a question correctly, display...

  • CS 1102 Unit 5 – Programming Assignment In this assignment, you will again modify your Quiz...

    CS 1102 Unit 5 – Programming Assignment In this assignment, you will again modify your Quiz program from the previous assignment. You will create an abstract class called "Question", modify "MultipleChoiceQuestion" to inherit from it, and add a new subclass of "Question" called "TrueFalseQuestion". This assignment will again involve cutting and pasting from existing classes. Because you are learning new features each week, you are retroactively applying those new features. In a typical programming project, you would start with the...

  • Written in Python In this lab, you are to build a trivia game. The game should...

    Written in Python In this lab, you are to build a trivia game. The game should present each question – either in order or randomly – to the player, and display up to four possible answers. The player is to input what they believe to be the correct answer.   The game will tell the player if they got it right or wrong and will display their score. If they got it right, their score will go up. If they got...

  • 3. You should test your program on other test cases (tdhat you make up) as well....

    3. You should test your program on other test cases (tdhat you make up) as well. Making up good test cases is a valuable programming skill, and is part of ensuring your code solution is correct. Problem A: Number game (20 points) Write a C++ program that will play the following game. Ask the user how many "rounds" you want to play and start at 10 points. Every turn you can add either 1 point (by choosing "a or 2...

  • Assignment 8.3: Phone Chatbot (10 pts) For this programming assignment, we write a basic chatbot program....

    Assignment 8.3: Phone Chatbot (10 pts) For this programming assignment, we write a basic chatbot program. For fun, try having a conversation with an online chatbot here or here. Some sources estimate that 25% of customer services will be handled by Chatbots in 2020, vs. 2% in 2017 (1). The chatbot we are designing must ask you the following questions: What is your name? What is your phone number? What is your phone plan? How many GB of data this...

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