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
  • 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...

  • 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...

  • 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...

  • 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...

  • Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create...

    Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create a completed program that prompts the user for the name of a data file, and reads the contents of that data file, then creates variables in a form suitable for computing the answer to some questions. The format should be in the same manner as the attached .py file. All subsequent assignment details (.py and .csv files) can be found at this...

  • In the original flashcard problem, a user can ask the program to show an entry picked...

    In the original flashcard problem, a user can ask the program to show an entry picked randomly from a glossary. When the user presses return, the program shows the definition corresponding to that entry. The user is then given the option of seeing another entry or quitting. A sample session might run as follows: Enter s to show a flashcard and q to quit: s Define: word1 Press return to see the definition definition1 Enter s to show a flashcard...

  • Hi there! I need to compare two essay into 1 essay, and make it interesting and...

    Hi there! I need to compare two essay into 1 essay, and make it interesting and choose couple topics which im going to talk about in my essay FIRST ESSAY “Teaching New Worlds/New Words” bell hooks Like desire, language disrupts, refuses to be contained within boundaries. It speaks itself against our will, in words and thoughts that intrude, even violate the most private spaces of mind and body. It was in my first year of college that I read Adrienne...

  • Hello! Could you please write your own four paragraph (5-6 sentences per paragraph) take away or...

    Hello! Could you please write your own four paragraph (5-6 sentences per paragraph) take away or reflection of the below information? Please complete in 24 hours if possible. Thank you! RIS BOHNET THINKS firms are wasting their money on diversity training. The problem is, most programs just don’t work. Rather than run more workshops or try to eradicate the biases that cause discrimination, she says, companies need to redesign their processes to prevent biased choices in the first place. Bohnet...

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