Skip to content
My workspace
  • AI Chat
  • Code
  • Report
  • Spinner
    import matplotlib.pyplot as plt
    import numpy as np
    
    x=[0, 30, 60, 90, 120, 150, 180, 210]
    y=[1.00, 1.01, 1.03, 1.03, 1.04, 1.06, 1.07, 1.07]
    
    coef = np.polyfit(x,y,1)
    poly1d_fn = np.poly1d(coef) 
    # poly1d_fn is now a function which takes in x and returns an estimate for y
    
    plt.plot(x,y, 'yo', x, poly1d_fn(x), '--k')
    plt.xlabel("Concentração")
    plt.ylabel("Densidade")
    
    plt.ylim(0.975, 1.10)
    x=[0, 4, 8, 12, 16, 20, 24, 28, 32, 36]
    y=[2.7, 10.8, 29.15, 50.4, 53.6, 54.1, 50.4, 54.7, 48.5, 51.4]
    plt.plot(x, y, '--k')
    import re
    
    lista = ["32 + 698", "3801 - 2", "45 + 43", "123 + 49"]
    def arithmetic_arranger(problems, show_answers = False):
        
        ## checar tamanho da lista
        if(len(problems) > 5):
            raise ValueError('Error: Too many problems.')
        
        problemas_formatados = list()
    
        ## obter o operador e numeros
        for problema in problems:
            operando1, operador, operando2 = problema.split()
            
            ## erros
            if(operador != "+" and operador != "-"):
                raise ValueError("Error: Operator must be '+' or '-'.")
                
            elif(len(operando1) > 4 or len(operando2) > 4):
                raise ValueError('Error: Numbers cannot be more than four digits.')
            
            elif(re.search("\D", operando1) or re.search("\D", operando2)):
                raise ValueError('Error: Numbers must only contain digits.')
                
            
            if(show_answers):
                ## resultado da conta
                if(operador == "+"):
                    res = int(operando1) + int(operando2)
                else:
                    res = int(operando1) - int(operando2)
                
                ## comprimento do problema
                comprimento = max(len(operando1), len(operando2), len(str(res))) + 2
            
                ## formata o problema
                problema_formatado_res = "{0:>{1}}\n{2} {3:>{4}}\n{5}\n{6:>{1}}".format(operando1, comprimento, operador, operando2, comprimento - 2, '-' * comprimento, res)
    
                ## adiciona o problema formatado à lista
                problemas_formatados.append(problema_formatado_res)  
            
            else:
                operando1, operador, operando2 = problema.split()
    
                comprimento = max(len(operando1), len(operando2)) + 2
    
                problema_formatado = "{0:>{1}}\n{2} {3:>{4}}\n{5}".format(operando1, comprimento, operador, operando2, comprimento - 2, '-' * comprimento)
    
                problemas_formatados.append(problema_formatado)
                    
            
        print("    ".join(problemas_formatados))
     
    
    arithmetic_arranger(lista)
        
    
    lista1 = ["32 + 698", "3801 - 2", "45 * 43", "123 + 49"]
    lista_op = list()
    lista_num = list()
    
    for conta in lista1:
            ind = conta.find("+")
            ind2 = conta.find("-")
    
            if(ind != -1):
                lista_op.append(conta[ind])
                lista_num.append(conta.split(" + "))
    
            elif(ind2 != -1):
                lista_op.append(conta[ind2])
                lista_num.append(conta.split(" - "))
                
    
    if(len(lista_num) < len(lista1)):
        print(True)
    
    print(lista_num)