Python
Page 1 of 9 COMP 151 – HW 9 Due date: 12/08/2020 11:59pm Build your own burger *This homework is a programming project. *You need to submit your python file on Blackboard. *Before starting the project, read this document THOROUGHLY. *To give you a better sense of this programming project, one example of the final output is given at the end of this document. Project Description In this project, you will implement a program where the user can build a burger. The user chooses toppings among patty, onion, cheese, and lettuce. Burger buns (top bun and bottom bun) are given by default. The main part of the program is displaying (printing) the current topping status. Whenever a topping is selected, the topping status shows which toppings are added so far to a burger. The program shows the topping status visually, and in the visual representation, it uses different text characters to indicate the corresponding topping as shown in the below table. Topping Type Representation Top Bun *************** ********************* *********************** Bottom Bun *********************** ********************* *************** Patty [=====================] Onion [ooooooooooooooooooooo] Cheese [+++++++++++++++++++++] Lettuce [~~~~~~~~~~~~~~~~~~~~~] An example of the topping status part is provided on the next page. It shows how the topping status is changed depending on which topping is chosen. You can also look at the final output result given at the end of this document to get a better sense of this topping status part. Note that the bottom bun is added after the user finishes to choose a topping (by selecting the ‘no more topping’ option.) Page 2 of 9 Page 3 of 9 Project Guideline Follow the below guideline to write a burger program. Part 0. Setup Programming Environment 1. Download the required files (byoBurger.py and topping.py) from Blackboard and save them under a folder that you want. 2. In Visual Studio Code, open the folder where you downloaded the above files. 3. If you can see the files below in Visual Studio Code, it is good to go:) ❖ In this project, byoBurger.py will work as the main program, and topping.py will work as a module. To run the burger program, you need to run byoBurger.py NOT topping.py. ❖ Inside byoBurger.py and topping.py, you will see some pre-written code and several comment blocks starting with Part 1, Part 2, Part 3, and Part 4. To finish the burger program, you need to complete each part of the program by following the below guideline. (For Example: To complete the section labeled “Part 1” in the code comments of the program, you need to follow Part 1 of this guide. Similarly, for parts 2, 3, and 4.) Part 1. Complete the topping module. 1. In this part, you need to complete the topping module (topping.py) that you downloaded from Blackboard. 2. Open (click) topping.py in Visual Studio Code. Page 4 of 9 3. Inside topping.py, there are six function definitions, and each one corresponds to each topping (top bun, bottom bun, patty, onion, cheese, and lettuce). Two topping functions (addTopBun() and addBottomBun()) are already defined. These functions append (add) a special strings to the toppingStatusList list. You can look at the table given in the above project description to see which string corresponds to which topping. Complete the definitions of the other functions (addPatty(), addOnion(), addCheese(), and addLettuce()) so that they also add the corresponding special strings to their input parameter, toppingStatusList. In the following parts, you need to write code in byoBurger.py. Thus, you need to open (click) byoBurger.py in Visual Studio Code. Part 2. Get a keyboard input from the user. 1. In this part, you write a code that receives keyboard input from the user. The input prompt should tell the user which keyboard input corresponds to which option. Look at the sample output at the end of this document for an idea of what this should look like. The below table shows which keyboard input denotes which option. Keyboard Input Option 0 No more topping 1 Patty 2 Onion 3 Cheese 4 Lettuce 9 Remove bottom topping Part 3. Perform proper action based on the received keyboard input. 1. In this part, you write a code that performs proper action based on the received keyboard input. The below table shows an action that the program needs to do depending on the keyboard input. Keyboard Input Action 0 Make the main while loop stop the repetition 1 Call addPatty() of topping module 2 Call addOnion() of topping module 3 Call addCheese() of topping module 4 Call addLettuce() of topping module 9 Remove the most recently added topping from toppingStatusList Page 5 of 9 ❖ In this part, you need to write a code that performs different actions based on the user’s input. Remember how we wrote a code of having different attack options based on the user’s input in the simple Pokémon battle program. Part 4. Display the topping status of a burger. 1. In this part, you write a code that displays (prints) the status of toppings as shown below so that the user knows which toppings are on a burger currently. 2. If you’ve successfully finished the previous parts, whenever the user selects a topping, the selected topping will be added to toppingStatusList of byoBurger.py. The program needs to display the topping status using the toppingStatusList. There are many ways to implement this part, and you can apply any approaches as you want. One approach is iterating over toppingStatusList and printing strings of the list line by line. 3. Note that after the program exits the main while loop (by selecting the ‘no more topping’ option), it needs to display the topping status again so that the program shows a complete burger figure with a bottom bun as shown below. Bonus Part. Print topping information of a burger 1. For this part, you write a code that prints information about toppings of the final burger. The information shows the number of each topping on the final burger. For example, if the final burger has two patties, one onion, one cheese, and two lettuces, your program needs to print the following message at the end. You added 2 patty You added 1 onion You added 1 cheese You added 2 lettuce You can also look at the final output of the program given at the end of this document to get a better sense of how this bonus part should look like. 2. Your code should work regardless of the order of topping selection. Let’s assume that the user chooses toppings in the following order: lettuce → onion → lettuce → patty → cheese → patty Page 6 of 9 In this case, your program needs to print the following message at the end. You added 2 patty You added 1 onion You added 1 cheese You added 2 lettuce Then, let’s assume that the user chooses the same toppings again but in a different order: onion → patty → patty → lettuce → cheese → lettuce In this case, your program still needs to print the same message at the end. You added 2 patty You added 1 onion You added 1 cheese You added 2 lettuce 3. There are many ways to solve this bonus part. This part has a format of an open question. You can use any approach to print the topping information. For example, you can create a new function. Also, you can modify the existing functions if you want. You can do whatever you want as long as your program does parts 1, 2, 3, and 4 correctly. 4. By completing this part successfully, you will get 5 bonus points. However, you are not required to complete the bonus part. (Parts 0, 1, 2, 3, and 4 are worth 25 points in total, and the bonus part is worth 5 bonus points. Therefore, the total possible points for the project is 30 points.) ❖ Do not forget that the user has an option to remove the recently added topping. When the user adds three patties, if the user removes two patties after that, your program should print the message ‘You added 1 patty’. You must account for any toppings the user decides to remove when reporting the final burger information for this bonus part. Submission Guideline 1. Upload the completed python files byoBurger.py and topping.py on Blackboard. 2. After you submit it, DOUBLE-CHECK whether you’ve submitted the correct files on Blackboard. Page 7 of 9 Final Output (continued on next page…) Page 8 of 9 (continued on next page…) Page 9 of 9