{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Logo\n", "\n", "# Practical Machine Learning for Natural Language Processing - 2023 SS \n", "\n", "### Assigment 2 - Generators and Classes \n", "\n", "In this assigment we are going to play with generators and instances/classes - structures that retain state. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1. Alea Iacta Est \n", "\n", "(a) Using [generator functions](https://github.com/rsouza/Python_Course/blob/master/Notebooks/Python_Basic/03_Functions.ipynb), create an object that emulates an eight-sided dice (1-8) that is biased, such that the probability of this generator function returning a certain value is proportional to the value itself (i.e. the face \"6\" is 3 times more likely to come out than face \"2\"); \n", "\n", " \"8-Dice\" \n", "\n", "(b) Using [Matplotlib](https://matplotlib.org/) plt.plot or plt.hist commands, show graphically the result of 10000 casts of the die; \n", "\n", "(c) Modify this generator function so that it terminates automatically when all possible values (1,2,3,4,5,6,7,8) have been cast at least once. In this case, it will return the total absolute time that has elapsed since the first iteration. (hint: a function can have both **return** and **yield** commands) " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# a)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# b)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# c)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2. A ticket to the first Class \n", "\n", "+ Create a Class called \"Elevator\". Each instance of this class receives as parameters the number of floors in the building and starts the elevator on the lowest floor. \n", "+ This Class should have methods and properties to allow the elevator to:\n", "

\n", " + Receive a call - user(s) press a button to go to specific floor(s); \n", " + Receive a floor as a destination - when users enter the elevator, each one may press a button to choose destination floor; \n", " + Store and inform which floor the elevator is at each moment(consider that trips for consecutive floors takes 5 seconds, and stopping takes 10 seconds); \n", " + Store and inform which users are in the elevator; \n", " + Store and inform the sequence of floors yet to be visited; \n", " + Store the number of times the elevator stopped in each floor (passing through the floor without \"stopping\" on the floor does not count); \n", " + Refuses commands to go to inexistent floors. \n", "

\n", "+ Simulate the behavior of the elevator serving ten users, each one calling from a random floor, and chosing a random destination floor. \n", "+ Graphically illustrate the current elevator position for the requested simulation. \n", "+ (BONUS) Create a smart building simulator, controlling calls made to n > 1 elevators and routing elevator properly. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.6" } }, "nbformat": 4, "nbformat_minor": 4 }