Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- As junior consultant you're asked to write a small notification system for passages based on logs from doors in secure area of company.
- # log format: {hour:(('Name','e/x',)),} e/x: Entry or eXit
- d_log = {7:(('Eric','e')),8:(('John','e'),('Michael','e'),('Eric','x')),9:(('Terry','e'), ('Eric','e'),('John','x'),('John','e')),10:(('John','x'),('Michael','x'))}
- code should print something like below output
- output:
- '''
- # Between 7 and 8 only Eric passed door.
- # Between 8 and 9 John, Michael and Eric passed door.
- # Between 9 and 10 Terry, Eric, John and John passed door.
- # Between 10 and 11 John and Michael passed door.
- '''
- # bonus: expand system to keep track of people entering / exiting and amount in area
- output:
- '''
- # Between 7 and 8 only Eric entered Secure Area. (1 inside)
- # Between 8 and 9 John and Michael entered, only Eric exited Secure area. (2 inside)
- # Between 9 and 10 Terry, Eric and John entered, only John exited Secure area. (4 inside)
- # Between 9 and 10 John and Michael exited Secure area. (2 inside)
- '''
- #Bonus 2. some suggestions/ examples of other ways to extend the code/ idea
- Remember it’s not about being first it’s about learning from doing and from what other people have done..
- so share your code in a format others can easily copy to test/ extend
- '''
- def print_Names_List(_list):
- if type(_list[0]) != tuple:
- return f"only {_list[0]} passed door."
- else:
- _list = [i[0] for i in _list]
- if len(_list) == 2:
- return f"{_list[0]} and {_list[1]} passed door."
- else:
- return ", ".join(_list[:-1]) + f" and {_list[-1]} passed door."
- d_log = {
- 7:(('Eric','e')),
- 8:(('John','e'),('Michael','e'),('Eric','x')),
- 9:(('Terry','e'), ('Eric','e'),('John','x'),('John','e')),
- 10:(('John','x'),('Michael','x'))
- }
- _hours = list(d_log.keys())
- # every transaction in the log is a tuple of 2 elements: (name, entrance/exit) as a value of the dictionary and the key is the hour
- for hour in _hours:
- transactions = list(d_log[hour])
- print(f'Between {hour} and {hour+1} {print_Names_List(transactions)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement