Created
March 24, 2022 10:49
-
-
Save duartejr/14ad71942ae1032ed1efc19b18491c69 to your computer and use it in GitHub Desktop.
maquina_refris_blue.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "nbformat": 4, | |
| "nbformat_minor": 0, | |
| "metadata": { | |
| "colab": { | |
| "name": "maquina_refris_blue.ipynb", | |
| "provenance": [], | |
| "authorship_tag": "ABX9TyOmp2VQkORdurlCYAwAtuUM", | |
| "include_colab_link": true | |
| }, | |
| "kernelspec": { | |
| "name": "python3", | |
| "display_name": "Python 3" | |
| }, | |
| "language_info": { | |
| "name": "python" | |
| } | |
| }, | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "view-in-github", | |
| "colab_type": "text" | |
| }, | |
| "source": [ | |
| "<a href=\"https://colab.research.google.com/gist/duartejr/14ad71942ae1032ed1efc19b18491c69/maquina_refris_blue.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "# Máquina de Refrigerante\n", | |
| "\n", | |
| "* ## 5 refrigerantes\n", | |
| " * coca (r0): 10 reais, 5 unidades\n", | |
| " * guarana (r1): 8 reais, 5 unidades\n", | |
| " * fanta (r2): 7 reais, 2 unidades\n", | |
| " * uva (r3): 5 reais, 0 unidades\n", | |
| " * sao_geraldo (r4): 10 reais, 10 unidades\n", | |
| "* ## O usuário seleciona um refri\n", | |
| " * Se estiver zerado emite uma mensagem\n", | |
| " * Se estiver no estoque\n", | |
| " * pagamento (pode dar erro)\n", | |
| " * desconta do estoque\n", | |
| " * soma o valor no caixa\n", | |
| " * libera o refri" | |
| ], | |
| "metadata": { | |
| "id": "sWattDZdWoer" | |
| } | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### Passo 1 declara dicionário dos refris" | |
| ], | |
| "metadata": { | |
| "id": "ZIW_FIj2XaLf" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 10, | |
| "metadata": { | |
| "id": "7ohyrtFlVnAj" | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "refris = {1:{'nome':'Coca-Cola', 'valor':10, 'quantidade':5},\n", | |
| " 2:{'nome':'Guaraná', 'valor':8, 'quantidade':5},\n", | |
| " 3:{'nome':'Fanta', 'valor':7, 'quantidade':2},\n", | |
| " 4:{'nome':'Uva', 'valor':5, 'quantidade':0},\n", | |
| " 5:{'nome':'São Geraldo', 'valor':10, 'quantidade':10}\n", | |
| " }" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### Sistema da máquina para uma operação" | |
| ], | |
| "metadata": { | |
| "id": "Kx4Fhu1VWc6B" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from random import randint\n", | |
| "\n", | |
| "caixa = 0\n", | |
| "\n", | |
| "while True:\n", | |
| " print('''\n", | |
| " TABELA DE OPÇÕES:\n", | |
| " 1 - Coca-Cola R$ 10,00\n", | |
| " 2 - Guaraná R$ 8,00\n", | |
| " 3 - Fanta R$ 7,00\n", | |
| " 4 - Uva R$ 5,00\n", | |
| " 5 - São Geraldo R$ 10,00\n", | |
| " ''')\n", | |
| "\n", | |
| " try:\n", | |
| " refri = int(input('Informe uma opção de refri: '))\n", | |
| " if refri not in range(1, 6):\n", | |
| " raise Exception('Oxe. Têm essa opção não. Tenta outra aí.')\n", | |
| " if refris[refri]['quantidade'] == 0:\n", | |
| " raise Exception('Têm mas acabou. Escolhe outro.')\n", | |
| " \n", | |
| " print('Você quer beber:', refris[refri]['nome'])\n", | |
| " print(f\"Temos {refris[refri]['quantidade']} unidades de {refris[refri]['nome']}.\")\n", | |
| " \n", | |
| " qtd = int(input('Informe a quantidade desejada: '))\n", | |
| " while qtd > refris[refri]['quantidade']:\n", | |
| " print('Oxe. Temos isso tudo não.')\n", | |
| " qtd = int(input('Informe a quantidade desejada: '))\n", | |
| " \n", | |
| " valor_compra = qtd * refris[refri]['valor']\n", | |
| " print(f\"O total da compra é R${valor_compra:.2f}\")\n", | |
| "\n", | |
| " senha = input('Digite a senha do cartão: ')\n", | |
| " if randint(1, 10) == 5:\n", | |
| " raise Exception('Deu erro no sistema. Tente novamente.')\n", | |
| " \n", | |
| " print('Compra finalizada. Curta seu refri geladinho.')\n", | |
| " refris[refri]['quantidade'] -= qtd\n", | |
| " caixa += valor_compra\n", | |
| "\n", | |
| " break\n", | |
| " except Exception as e:\n", | |
| " print(e)\n", | |
| " continue\n", | |
| "\n" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "DoOM2-XHYGdG", | |
| "outputId": "53a4f1d5-d785-4830-8fa6-16261d6ade3c" | |
| }, | |
| "execution_count": 14, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "\n", | |
| " TABELA DE OPÇÕES:\n", | |
| " 1 - Coca-Cola R$ 10,00\n", | |
| " 2 - Guaraná R$ 8,00\n", | |
| " 3 - Fanta R$ 7,00\n", | |
| " 4 - Uva R$ 5,00\n", | |
| " 5 - São Geraldo R$ 10,00\n", | |
| " \n", | |
| "Informe uma opção de refri: 5\n", | |
| "Você quer beber: São Geraldo\n", | |
| "Temos 10 unidades de São Geraldo.\n", | |
| "Informe a quantidade desejada: 2\n", | |
| "O total da compra é R$20.00\n", | |
| "Digite a senha do cartão: 1234\n", | |
| "Compra finalizada. Curta seu refri geladinho.\n" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### Relatório da máquina" | |
| ], | |
| "metadata": { | |
| "id": "_OAmhOQ9iquM" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "print('Relatório da máquina')\n", | |
| "print(\"-\"*50)\n", | |
| "print(f'Valor em caixa = R${caixa:.2f}')\n", | |
| "print(\"-\"*50)\n", | |
| "print('Estoque')\n", | |
| "print(\"-\"*50)\n", | |
| "for refri in refris:\n", | |
| " print(f\"Produto: {refris[refri]['nome']}\")\n", | |
| " print(f\"Quantidade: {refris[refri]['quantidade']}\")\n", | |
| " print(\"-\"*50)" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "CxOqt1csaty6", | |
| "outputId": "fbbdf734-430f-4ce6-925c-0461d6b80126" | |
| }, | |
| "execution_count": 15, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "Relatório da máquina\n", | |
| "--------------------------------------------------\n", | |
| "Valor em caixa = R$20.00\n", | |
| "--------------------------------------------------\n", | |
| "Estoque\n", | |
| "--------------------------------------------------\n", | |
| "Produto: Coca-Cola\n", | |
| "Quantidade: 5\n", | |
| "--------------------------------------------------\n", | |
| "Produto: Guaraná\n", | |
| "Quantidade: 5\n", | |
| "--------------------------------------------------\n", | |
| "Produto: Fanta\n", | |
| "Quantidade: 2\n", | |
| "--------------------------------------------------\n", | |
| "Produto: Uva\n", | |
| "Quantidade: 0\n", | |
| "--------------------------------------------------\n", | |
| "Produto: São Geraldo\n", | |
| "Quantidade: 8\n", | |
| "--------------------------------------------------\n" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "" | |
| ], | |
| "metadata": { | |
| "id": "liEeenJJh_g2" | |
| }, | |
| "execution_count": null, | |
| "outputs": [] | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment