CptS 111 Introduction to Algorithmic Problem Solving

Washington State University

Gina Sprint

PA3 Conditionals (75 pts)

Due Monday, October 10 at Midnight.

Learner Objectives

At the conclusion of this programming assignment, participants should be able to:

  • Evaluate Boolean expressions
  • Apply relational and logical operators
  • Implement if statements

Prerequisites

Before starting this programming assignment, participants should be able to:

  • Get input from the user
  • Display output to the user
  • Define and call functions

Acknowledgments

Content used in this assignment is based upon information in the following sources:

  • No sources to cite

Overview and Requirements

Write an "are you a fan" quiz program (quiz.py). The program will quiz the user on a topic of your choosing (keep the topic appropriate!!). For quiz ideas, check out this website.

Note: Please cite all sources you use in your code.

Program Details

Your quiz must contain 10 questions. These 10 questions include at least 2 of each of the following different types of questions:

Multiple choice (5 options a-e)

The user enters in a character "a" through "e" for their answer.

Example:

1) What is the a rough estimate of the population of New York City? Please enter a character a-e.
a) 1 million
b) 3 million
c) 5 million
d) 8 million
e) 10 million

Note: The answer is d) 8 million!

Numeric Response

The user enters in a numeric response to an open ended question. I recommend prompting the user to enter an integer. If you choose to use floats, be specific to the user about how they should enter their response (i.e. rounded and/or a certain number of decimal places).

Example:

How many states are there in the United States? Please enter an integer.

Note: The answer is 50!

True/False (Boolean)

The user enters 1 or 0 in response to a statement. Convert the string returned by input() into an integer, and then into a Boolean with the bool() type cast. Then compare the response to the reserved keywords True or False.

Example:

Alaska was the last state to enter the Union, true or false? Please enter 1 for True or 0 for False.

Note: The answer is False! Hawaii was the last state to enter the Union.

Additional requirements:

  1. For each question:
    1. Define a function. The function should return the following:
      1. 1 (int) if the user answered correctly
      2. 0 (int) if the user answered incorrectly
    2. Explicitly tell the user the format in which they should enter their response.
    3. Number each question.
    4. Check the user's answer for correctness using an if-else structure. If the user answers correctly, inform the user. Otherwise, provide the correct answer to the user.
  2. Define a main() function that drives your program. main() should count the number of correct answers (this is the user's quiz score).
  3. At the end of the quiz, tell the user their final score, plus a fun statement about how much of a "fan" they are of the quiz's topic (use an if-elif-else structure, which means you need at least 3 different fun statements based on the user's score).

Example Run

Here is a shortened example run of a quiz based on Game of Thrones. Credit for much of the content goes to these two online quizzes: Q1 and Q2.

Welcome to the Game of Thrones Quiz!!
1) Which Dire-wolf belonged to Robb? Please enter a character a-e.
a) Lady
b) Summer
c) Grey Wind 
d) Nimeria
e) Ghost
b
Sorry, that is wrong. The answer is c) Grey Wind.

2) How many dragons does Daenerys own? Please enter an integer.

3

[output removed for brevity]

9) Name one of Daenerys' dragons. Please enter a string in all lower case.

drogon

10) Who wins the Kingsmoot on the iron isles? Please enter a character a-e.
a) Asha Greyjoy
b) Reek
c) Balon Greyjoy
d) Euron Greyjoy
e) Ramsay Bolton

d
You scored 9 questions correctly. Wow, you know your Game of Thrones!

Submitting Assignments

  1. Use the Blackboard tool https://learn.wsu.edu to submit your assignment to your TA. You will submit your code to the corresponding programming assignment under the "Content" tab. You must upload your solutions as <your last name>_pa3.zip by the due date and time.
  2. Your .zip file should contain your .py file.

Grading Guidelines

This assignment is worth 75 points. Your assignment will be evaluated based on a successful compilation and adherence to the program requirements. We will grade according to the following criteria:

  • 30 pts for 6 functions defined to represent:
    • (10 pts) At least 2 multiple choice questions
    • (10 pts) At least 2 numeric response questions
    • (10 pts) At least 2 Boolean questions
  • 5 pts for 4 functions defined to represent 4 additional questions (your choice on question type)
  • 10 pts for proper use of function return values to denote correct/incorrect answers
  • 5 pts for correct main() function
  • 5 points for numbering questions and stating the response format in your question prompts
  • 5 points for letting the user know the correct answer when they are wrong
  • 10 points for displaying a message at the end of the quiz based on the number of correct responses
  • 5 pts for adherence to proper programming style and comments established for the class