# Chapter Four: Making Decisions

## Activity: Blue Moon

In this chapter, you learned how to test numeric and string values using conditional operators (e.g. <>==) and join logical expressions using logical operators (andornot). You can then use "ifelif and else" statements to run certain blocks of code based on the True or False results of these logical expressions.

You are going to put these skills to work by creating a program that selects a song title based on certain input values. Your program will use logical expressions and "if / elif / else" statements to display a selected song based on the user's inputs. Don't forget, you should have already selected and be comfortable with a coding platform for your chapter activities. You will be using our online Python engine or coding your own external Python files and submitting them to your teacher.

### Activity Requirements

• Is there a blue moon tonight (Yes / No)?
• What is the day of the week (Monday - Sunday)?
• What is the day of the month (1 - 31)?

Next, your program will select and print a single song title to the screen based on the user's answers. You will use the following selection logic:

• If the answer to the "blue moon" question is "Yes", always display the song title "Once in a Blue Moon".
• Else if the answer to the day of the month question is a number less than or equal to 7,
• If the week day is "Monday", display the song title "Manic Monday"
• Else if the week day is "Tuesday", display the song title "Tuesday's Gone"
• Else if the week day is "Wednesday", display the song title "Just Wednesday"
• Else if the week day is "Thursday", display the song title "Sweet Thursday"
• Else if the week day is "Friday", display the song title "Friday I'm in Love"
• Else if the week day is "Saturday", display the song title "Saturday in the Park"
• Else if the week day is "Sunday", display the song title "Lazing on a Sunday Afternoon"
• Else on any other unrecognized input, display the song title "Days of the Week"
• Else (for all other days of the month), display the song title "Day Dream Believer"

The following three samples demonstrate the program input and output for some of these cases:

Is there a blue moon tonight (Yes / No)? Yes
What is the day of the week (Monday - Sunday)? Sunday
What is the day of the month (1 - 31)? 4
Play song 'Once in a Blue Moon'
Is there a blue moon tonight (Yes / No)? No
What is the day of the week (Monday - Sunday)? Monday
What is the day of the month (1 - 31)? 2
Play song 'Manic Monday'
Is there a blue moon tonight (Yes / No)? No
What is the day of the week (Monday - Sunday)? Wednesday
What is the day of the month (1 - 31)? 35
Play song 'Day Dream Believer'

### Getting Started

Your first task is to prompt the user for three input values. Use the input() function to display the question prompt and to receive the string answer.

1. Start your Python code with a comment at the top showing your name.
2. Store the blue moon Yes/No response in a variable named blueMoon
3. Store the day of the week response in a variable named weekDay
4. Store the day of the month response in a variable named dayOfMonth
• Don't forget to use the int() function to convert the user's day of the month response to an integer number when assigning the value to dayOfMonth

Once you have successfully gathered the user's input and initialized your variables, you will need to write the "if / elif / else" logic to meet the program requirements. There are multiple ways you could write your code to get the same results. However, the Activity Requirements give you some useful guidance that can be closely followed.

1. Use the bulleted steps listed in the Activity Requirements above to guide your work. The "If", "Else if" and "Else" phrases are strong hints to use Python "if", "elif" and "else" statements to test conditions and perform the work.
2. Use the indentations of the bulleted steps as strong hints as to which statements should be nested inside of other statements. For example, the "if / else if / else" series of tests around the week day (Monday, Tuesday, etc.) should be entirely contained within a block of code that runs only when the day of the month is less than or equal to 7.
3. Ensure that every possible path through your program produces some song title output, as described by the activity requirements. If the user enters a valid integer number for the last question, there should be no path through the code that does not produce any output.

Hints:

The following statement can be used to gather the third user input value (an integer day of the month):

dayOfMonth = int(input("What is the day of the month (1 - 31)? "))

Assuming you have declared the blueMoon and other variables as listed above, the following code will help you meet the first condition to select the "Once in a Blue Moon" song whenever the answer to the first question is "Yes".

if (blueMoon == "Yes"):
print("Play song 'Once in a Blue Moon'")
elif ...:

You will continue by completing the "elif" and other logical conditions and statements as described above. Don't forget to indent blocks of code that should be run inside an "if", "elif" or "else" statement when those cases are chosen.

The Python equality operator (==) will compare strings exactly as they are written in a case-sensitive manner. So, "Yes", "YES" and "yes" are all three different things. "Yes" == "yes" is False, while "Yes" == "Yes" is True. When entering input values, be careful to type in the Yes/No answers and the days of the week exactly as they are specified with a capital letter at the beginning of each.

Extra Challenge:

Can you enhance your logic to detect both capitalized and lower-case user inputs? For example, what kind of logical expression can you write to see if the answer to the first question is either "Yes" or "yes"? What kind of logical expression would detect "Monday" or "monday" for that day of the week? See if you can improve your program to accept both kinds of user input. You can use one of the logical operators (andornot) to extend your logical expressions.

### Activity Results

When you are done, run your code and try different combinations of input values to check all possible results. There are 10 different song titles listed in the Activity Requirements, so you should be able to produce each song at least one time with the correct inputs. You can use the following test cases to verify each of your song outputs.

User inputs: Yes, Monday, 25 (should select "Once in a Blue Moon")

Is there a blue moon tonight (Yes / No)? Yes
What is the day of the week (Monday - Sunday)? Monday
What is the day of the month (1 - 31)? 25
Play song 'Once in a Blue Moon'

User inputs: No, Monday, 1 (should select "Manic Monday")

Is there a blue moon tonight (Yes / No)? No
What is the day of the week (Monday - Sunday)? Monday
What is the day of the month (1 - 31)? 1
Play song 'Manic Monday'

User inputs: No, Tuesday, 2 (should select "Tuesday's Gone")

Is there a blue moon tonight (Yes / No)? No
What is the day of the week (Monday - Sunday)? Tuesday
What is the day of the month (1 - 31)? 2
Play song 'Tuesday's Gone'

User inputs: No, Wednesday, 3 (should select "Just Wednesday")

Is there a blue moon tonight (Yes / No)? No
What is the day of the week (Monday - Sunday)? Wednesday
What is the day of the month (1 - 31)? 3
Play song 'Just Wednesday'

User inputs: No, Thursday, 4 (should select "Sweet Thursday")

Is there a blue moon tonight (Yes / No)? No
What is the day of the week (Monday - Sunday)? Thursday
What is the day of the month (1 - 31)? 4
Play song 'Sweet Thursday'

User inputs: No, Friday, 5 (should select "Friday I'm in Love")

Is there a blue moon tonight (Yes / No)? No
What is the day of the week (Monday - Sunday)? Friday
What is the day of the month (1 - 31)? 5
Play song 'Friday I'm in Love'

User inputs: No, Saturday, 6 (should select "Saturday in the Park")

Is there a blue moon tonight (Yes / No)? No
What is the day of the week (Monday - Sunday)? Saturday
What is the day of the month (1 - 31)? 6
Play song 'Saturday in the Park'

User inputs: No, Sunday, 7 (should select "Lazing on a Sunday Afternoon")

Is there a blue moon tonight (Yes / No)? No
What is the day of the week (Monday - Sunday)? Sunday
What is the day of the month (1 - 31)? 7
Play song 'Lazing on a Sunday Afternoon'

User inputs: No, oops, 1 (should select "Days of the Week") - this tests unrecognized user input for the day of the week

Is there a blue moon tonight (Yes / No)? No
What is the day of the week (Monday - Sunday)? oops
What is the day of the month (1 - 31)? 1
Play song 'Days of the Week'

User inputs: No, Monday, 20 (should select "Day Dream Believer")

Is there a blue moon tonight (Yes / No)? No
What is the day of the week (Monday - Sunday)? Monday
What is the day of the month (1 - 31)? 20
Play song 'Day Dream Believer'

### Activity Rubric

PointsDescription
10Song "Once in a Blue Moon" selected under the right conditions
10Song "Manic Monday" selected under the right conditions
10Song "Tuesday's Gone" selected under the right conditions
10Song "Just Wednesday" selected under the right conditions
10Song "Sweet Thursday" selected under the right conditions
10Song "Friday I'm in Love" selected under the right conditions
10Song "Saturday in the Park" selected under the right conditions
10Song "Lazing on a Sunday Afternoon" selected under the right conditions
10Song "Days of the Week" selected under the right conditions
10Song "Day Dream Believer" selected under the right conditions

Remember that case-sensitivity is important, so be sure your displayed song titles exactly match our examples.

End of Activity