Problem 172756 · easy · Phase 01 Prerequisites & Setup

Restaurant Tip Suggestion

conditionals · arithmetic

A restaurant app suggests a tip. Write suggested_tip(bill, rating, party_size) that returns the tip amount as a float rounded to 2 decimals:

  • parties of 6 or more always get an automatic 18% tip, whatever the rating
  • otherwise a rating of 5 means 20%, a rating of 4 means 15%, a rating of 3 means 10%, and any lower rating means 5%

Examples

Input:  bill = 100, rating = 5, party_size = 2
Output: 20.0

Input:  bill = 80, rating = 3, party_size = 2
Output: 8.0

Input:  bill = 50, rating = 1, party_size = 8
Output: 9.0

Constraints

  • 0 <= bill <= 10000
  • 1 <= rating <= 5, 1 <= party_size <= 50 (integers)

Goals

  • Let one rule override a whole chain of others
  • Turn a percentage into an amount and round it
Starting Python…