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
| def numero_perfeito(num): | |
| cont=1 | |
| soma=0 | |
| while cont<num: | |
| if (num%cont)==0: | |
| soma=soma+cont | |
| cont+=1 | |
| if soma==num: | |
| return True | |
| else: |
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
| import math | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| class KNNRegressao: | |
| def __init__(self, x, y, K=3): | |
| self.n_amostras = len(x) | |
| self.n_attrs = len(x[0]) | |
| self.x, self.y, self.K = x, y, K |
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
| # distância euclidiana | |
| import math | |
| v1 = [1.2, 2, 3.8, 4.5] | |
| v2 = [0.5, 4.5, 9.6, 3.4] | |
| def dist_euclidiana(v1, v2): | |
| dim, soma = len(v1), 0 | |
| for i in range(dim): |
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
| ''' | |
| Extração de dados de um arquivo CSV do Google Forms com nome,e-mail | |
| ''' | |
| import random | |
| pessoas = {} | |
| with open('sorteio.csv', 'r', encoding='utf-8') as f: | |
| lines = f.readlines()[1:] | |
| for line in lines: | |
| dados = line.split(',') |
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
| ''' | |
| Implementação do Algoritmo Bubble Sort | |
| Animação: https://www.youtube.com/watch?v=lyZQPjUT5B4 | |
| ''' | |
| l = [30, 50, 10, 35, 70, 45, 80, 100, 22] | |
| tam_l = len(l) | |
| # bubble sort | |
| for i in range(tam_l): |
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
| # PyNotePad | |
| from tkinter import * | |
| import tkinter.filedialog as fdialog | |
| from tkinter import messagebox | |
| nome_arquivo = 'my_file.txt' | |
| def novo_arquivo(): | |
| text_box.delete(0.0, END) |
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
| def buscar_email(self, email): | |
| """Busca um cliente pelo email""" | |
| try: | |
| cursor = self.conexao.cursor() | |
| # obtém todos os dados | |
| cursor.execute("SELECT * FROM clientes WHERE email = ?",[(email)]) | |
| cliente = cursor.fetchone() | |
| if cliente: |
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
| ''' | |
| Algoritmos gulosos | |
| - Sempre escolhe a alternativa que parece mais promissora naquele instante | |
| - NUNCA reconsidera essa decisão | |
| - Uma escolha que foi feita NUNCA é revista | |
| - Não há backtracking | |
| - A escolha é feita de acordo com um criterio guloso - decisão localmente ótima. | |
| - Nem sempre dão soluções ótimas | |
| Problema do Troco (Troco mínimo) |
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
| ''' | |
| Get Bitcoin Value | |
| http://api.coindesk.com/v1/bpi/currentprice.json | |
| ''' | |
| import urllib.request, json, time | |
| def obter_valor(): | |
| try: | |
| url = "http://api.coindesk.com/v1/bpi/currentprice.json" |
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
| ''' | |
| Fibonacci: 1, 1, 2, 3, 5, 8, 13, 21, 34 ... | |
| F(1) = F(2) = 1 | |
| F(n) = F(n - 1) + F(n - 2) | |
| F(3) = F(2) + F(1) = 1 + 1 = 2 | |
| F(4) = F(3) + F(2) = 2 + 1 = 3 | |
| ''' | |
| MAX_N = 100 | |
| valores = [0] * MAX_N |