Overview

The goal of this assignment is to allow you to practice employing conditional execution in the Python programming language. To record your solutions and answers, create a new Jupyter Notebook named Notebook02.ipynb and use this notebook to complete the following activities and answer the corresponding questions.

Make sure you label your activities appropriately. That is for Activity 1, have a header cell that is titled Activity 1. Likewise, use the Markdown cells to answer the questions (include the questions above the answer).

This Notebook assignment is due midnight Thursday, September 8 and is to be done individually.

Activity 1: Magic 8-Ball

For this activity, you are to implement a program that simulates a Magic 8-Ball by prompting the user for a question and then randomly printing one of the following outcomes:

  1. It is certain
  2. It is decidedly so
  3. Without a doubt
  4. Yes definitely
  5. You may rely on it
  6. As I see it, yes
  7. Most likely
  8. Outlook good
  9. Yes
  10. Signs point to yes
  11. Reply hazy try again
  12. Ask again later
  13. Better not tell you now
  14. Cannot predict now
  15. Concentrate and ask again
  16. Don't count on it
  17. My reply is no
  18. My sources say no
  19. Outlook not so good
  20. Very doubtful

A transcript of the program should go as follows:

What is your question? Will Notre Dame win the national championship this year?
Without a doubt

Hint: random.choice

Questions

After you have completed the program above, answer the following questions:

  1. Did you use a data structure in your program? If so, which one and why? Could you have used another one instead (which one)?

  2. Execute your program a few times. Is your Magic 8-Ball positive, neutral, or negative? If you wanted to make an overly pessimistic or negative Magic 8-Ball, what could you do to accomplish that without removing any positive or neutral answers?

Activity 2: Stadium Seating

For this activity, you are to write a program that helps visitors to Notre Dame stadium figure out the best gate to enter through for their specified section.

According to the diagram to the right, your program should follow the gate assignments below:

Gate Sections
A 1, 2, 3, 4, 5, 6, 7, 8, 9, 101, 102, 103, 104, 105, 106, 107, 108, 109
B 10, 11, 12, 13, 14, 15, 16, 17, 18, 110, 111, 112, 113, 114, 115, 116, 117, 118
D 19, 20, 21, 22, 23, 24, 25, 26, 27, 119, 120, 121, 122, 123, 124, 125, 126, 127
E 28, 29, 30, 31, 32, 33, 34, 35, 36, 128, 129, 130, 131, 132, 133, 134, 135, 136

A transcript of the program should go as follows:

What is your Section Number? 6
You should enter Gate A for Section 6.

What is your Section Number? 32
You should enter Gate E for Section 32.

What is your Section Number? 53
I'm sorry but there isn't a Section 53.

Questions

  1. Describe the control flow of your program. Did you use alternative execution, chained conditionals, or nested conditionals?
  2. Re-implement your program by using the in operator and a few data structures. If your program is already implemented in this fashion, then re-implement to not use in and any data structures.

    Which solution do you prefer and why?

Activity 3: Fizz Buzz Boom

For this activity, you are to write a solution to a variant of the infamous FizzBuzz problem:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

For this activity, the problem has an additional constraint: for multiples of seven print "Boom", instead of the number and regardless of the above rules.

To iterate or loop over the numbers from 1 to 100, you can use the following for loop:

for number in range(1, 101):
    # Conditional statements...

Inside the for loop, you should add some conditional statements that solve the FizzBuzzBoom problem as described above.

The output of your program should be something like the following:

1
2
Fizz
4
Buzz
Fizz
Boom
8
Fizz
Buzz
11
Fizz
13
Boom
FizzBuzz
...

Hint: You will need to use the % (modulo) operator.

Internet Resources

While you are generally encouraged to use the Internet as a resource for programming assignments, for this problem, you are asked to refrain from looking up information specific to the FizzBuzz problem because the question is so popular and there are many solutions available.

Remember that any code you submit must be your own and that you must be able to explain every line of your program.

Questions

After you have completed the program above, answer the following questions:

  1. Describe the control flow of your program. Did you use alternative execution, chained conditionals, or nested conditionals?

  2. Why do you think this question often trips up candidates interviewing for programming positions? What was the trickiest part of this problem for you?

Submission

To submit your Notebook, follow the same directions for Notebook 01, except store this notebook in the notebook02 folder.