0% found this document useful (0 votes)
2 views4 pages

Assignment3

Uploaded by

valentoninelli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Assignment3

Uploaded by

valentoninelli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ISM3230 Assignment 3 – Dictionaries

TASKS

In this assignment, you are still working at the same ice cream store company as Lab 10. You have just
demonstrated your initial prototype (your code from Lab 10), and the stakeholders have asked for some
additional functionality in the next Agile sprint iteration. Functionally, this assignment asks you to take
the code from Lab 10 and extend it. Make sure that Lab 10 code works as specified in the Lab 10
specification document before you start on the assignment.

Your task is to extend the Lab 10 code in three areas:

1. Expand the offerings of flavors and toppings by two additional items of your choice. Add two
more flavors and their prices to the flavors_available dictionary and add two toppings
and their prices to the toppings_available dictionary.

2. Add an error-checking loop for the user input of flavor selection. Currently, the user is required
to enter the flavor exactly as it is stored in the flavors_available dictionary (except
capitalization). If the user enters an incorrect flavor, a KeyError is raised because that input is
not found in the flavors_available dictionary. For example, if the user enters “van” as a
flavor, the program stops with an error:

Modify the code by adding an appropriate loop so that the program will keep asking for a flavor
whenever a non-existent flavor is entered. Additionally, make sure that the user input is case-
insensitive, as was already specified in the Lab10 document. Use an f-string as the prompt in the
input function to indicate the error message with the following wording: 'Flavor "flavor"
not found, please enter a valid flavor: '. For example:
3. Add an error-checking loop for the user input of topping selection. Currently, the user is
required to enter the topping exactly as it is stored in the toppings_available dictionary
(except capitalization). If the user enters an incorrect topping, a KeyError is raised because
that input is not found in the toppings_available dictionary. For example, if the user
enters “whipped” as a topping, the program stops with an error:

Modify the code by adding an appropriate loop so that the program will keep asking for a
topping whenever a non-existent topping is entered. Additionally, make sure that the user input
is case-insensitive, as was already specified in the Lab10 document. Use an f-string as the
prompt in the input function to indicate the error message with the following wording:
'Topping "topping" not found, please enter a valid topping: '. For
example:

Note that the Boolean condition for this loop will be slightly more complex than the one for
flavors because it has to account for the stop word. The loop should keep looping through the
body code as long as the input is not found in the dictionary. However, the stop word is also not
found in the dictionary – you want to stop looping if the stop word is entered. The result will be
a complex Boolean that considers user input with respect to the toppings_available, and also
with respect to the stop word.

Once you have gotten an input that is either a valid topping or ‘stop’, then your while loop
should stop.
4. Format the output of the code according to the following specification. Refer to the slides on
formatting with f-strings for the appropriate syntax.
a. Print the flavor names in title case.
b. Format the flavor list to have a 20-character wide column with flavor names, followed
by the prices. Make the flavor names indented by 2 spaces from the left edge. Make
sure the colon : follows the flavor name immediately.
Hint: Use string concatenation first to create the appropriate output for the flavor name
column, then use the f-string formatting to give it a width of 20.
c. Add a dollar sign $ in front of the price value, and format the price number to be a
floating point value with 2 decimal places.

d. Apply the same formatting for the list of toppings:

e. Apply the same formatting to the printout of the total order:

5. When your code prints the output as in the Sample output, upload your code to the canvas
dropbox.
SAMPLE OUTPUT

Use the sample output to check for the correct formatting and functionality of your code. The output
will vary according to the user input:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy