Python 3.4

Checkout System

  • Fully automatically graded on code quality, style, structure and functionality
  • Students write their solution in an online IDE in their LMS
  • Check for Python code plagiarism

Pre-requisites:

  • Input function.
  • Functions.
  • Loops.

Learning goals:

  • Learn how to put functions into practice.
  • Learn how to put loops into practice.
Get access to an autograder, plagiarism checker and online IDE for this assignment now!

Task:

Great news! You just got a request to develop software for one of the world’s busiest hotels: Habbo Hotel. Habbo Hotel is a Finnish online community that was founded in 2000, being one of the first big global online games. In Habbo Hotel, players can design their own rooms, walk around the public spaces of the hotel and chat with each other. Now that Habbo Hotel has “hotels” in 9 different languages and millions of users, they want to expand their businesses and set up a Hotel Bar. To set this up they have requested your help.

Habbo Hotel has requested you to develop a checkout system for their new Hotel Bar. They requested the following functionality:

1. The user should be prompted with the following menu and prices (you may use a multiline string to print this, read more here):

-!- CODE language-text -!-1. Habbeer ($3.50)
2. Wine ($4.00)
3. Java Coffee ($2.50)
4. Apple Juice ($6.00)
5. Root Access Beer ($1.75)

2. The user is asked what they want to order, they should input the numbers they want to order. They can input multiple items, see:

-!- CODE language-text -!-Please write down your order: 1154

The above would be an order of two Habbeers, a Root Access Beer and an Apple Juice.

3. Loop through the inputted string and calculate the total price of the order by adding the individual prices. You can easily loop through a string by character using `for character in string:`.

4. Now, in a function defined as `add_percentage(price, percentage=15)` add the given tax to the given price and return that number. In this case, `percentage` has a default value of `15` and thus does not have to be given as an argument when calling the function. You may be able to re-use this function in the next step. The default tax for the Habbo Bar is `15`.

5. Then, in a function called `add_tip(price)`, ask the user what percentage of the total price (including tax) they want to give as a tip using `input()`, add this percentage to the price and return:

-!- CODE language-text -!-How much tip would you like to give? 15

Use input validation in this step: the number has to be a positive integer. Use awhile-loop to continuously ask the user for input and only break if the input is correct.

6. Finally, print out the total price to the customer of Habbo Bar (round to two decimals):

-!- CODE language-text -!-Total price: $19.51

Write this all in a script called `checkout_system.py`, which should call a `main()` function from the `if __name__ == "__main__":` block that calls all functions as needed. Next to the `main()` function, you are required to implement at least the other two functions mentioned above, but are encouraged to split up your implementation in as many (logical) subtasks as possible.

Example usage:

-!- CODE language-bash -!-$ python3 checkout_system.py
1. Habbeer ($3.50)
2. Wine ($4.00)
3. Java Coffee ($2.50)
4. Apple Juice ($6.00)
5. Root Access Beer ($1.75)

Please write down your order: 1154
How much tip would you like to give? 15

Total price: $19.51

$ python3 checkout_system.py
1. Habbeer ($3.50)
2. Wine ($4.00)
3. Java Coffee ($2.50)
4. Apple Juice ($6.00)
5. Root Access Beer ($1.75)

Please write down your order: 3
How much tip would you like to give? word
How much tip would you like to give? again a word
How much tip would you like to give? 5

Total price: $3.02

Learn more:

Start teaching Python now

CodeGrade is your virtual teaching assistant for your coding classroom. You teach, CodeGrade takes care of the rest.

With our 40+ built-in fully automatically graded Introduction to Python assignments for university-level courses, you can start teaching Python at your institution with confidence now. Or, scale your classroom with CodeGrade's tools.

Book a personal 30-minute demo now and we'll show you how to get started with CodeGrade in less than 1 hour!

Book a demo now!

Happy educators

  • Educators who use CodeGrade have less stress.
  • Educators who use CodeGrade have happier and more successful students.
  • Educators who use CodeGrade have a simpler teaching workflow.

Schedule a personalized tour of CodeGrade today.