#!/usr/bin/python3 # -*- coding: utf-8 -*- """ PRE-INTERVIEW ASSIGNMENT Thank you for your interest in the position. Before we take you in for an interview, we would like to ask you to solve the following tasks. Give it 1 to 3 hours of your best effort and email the source code back to us. Good luck! :) ==TASKS== 1. The program below contains a bug, tagged with a FIXME comment in the code. Fix it, changing as little code as necessary. Save the result as task1.py. 2. With the result from task 1, refactor the code to make it easier to read, maintain, and extend. You may also rewrite the program using a different programming language or framework if you are feeling creative. Save the result as task2. 3. With the result from task 2 as your starting point, implement the feature specified below. Save the result as task3.py (or task3. if you use another language). Specification: There should be a finite amount of servings for each dish on the menu, i.e. 15 Dagens, 2 Vegetar, 5 Halal. Requesting a dish that has no servings left should return the message "Sorry, no more left of today." Example run: What would you like today? (type 'how is business?' to attempt small talk, or 'not hungry' to stop) > Vegetar Vegetar, here you go. What would you like today? (type 'how is business?' to attempt small talk, or 'not hungry' to stop) > Vegetar Vegetar, here you go. What would you like today? (type 'how is business?' to attempt small talk, or 'not hungry' to stop) > Vegetar Sorry, no more left of today. What would you like today? (type 'how is business?' to attempt small talk, or 'not hungry' to stop) > [...] """ items = [ 'Dagens', 'Vegetar', 'Halal' ] prices = [ 53.90, 42.50, 59.90 ] meal_sum = 0 total_sum = 0 def sell(item): global meal_sum global total_sum if item == 'Dagens': meal_sum += prices[0] total_sum += prices[0] print("Dagens, here you go.\n") elif item == 'Vegetar': meal_sum += prices[1] total_sum += prices[1] print("Vegetar, here you go.\n") elif item == 'Halal': meal_sum += prices[2] total_sum += prices[2] print("Halal, here you go.\n") else: print("%s is not on the menu!\n" % item) def empty_cash_registry(): global meal_sum meal_sum = 0 print("Cash registry emptied. Thieves be warned!\n") def cafeteria(): global meal_sum global total_sum print("What would you like today? (type 'how is business?' to attempt small talk, or 'not hungry' to stop)") user_input = input("> ") while user_input != 'not hungry': question = 0 if user_input == 'how is business?': question = 1 if total_sum == 0: print("Not good so far. No one seems to be hungry today!\n") elif total_sum > 0: print("Alright. Could have been better\n") elif total_sum > 500: # FIXME: this doesn't work properly print("Excellent! Lots of hungry students around today.\n") if question == 0: sell(user_input) if meal_sum > 200: empty_cash_registry() print("What would you like today? (type 'how is business?' to attempt small talk, or 'not hungry' to stop)") user_input = input("> ") print("Welcome back later!\n") if __name__ == '__main__': cafeteria()