Advertisement
DomMisterSoja

3.1 Definitivo

Sep 30th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.72 KB | None | 0 0
  1. import random
  2. from time import sleep
  3.  
  4. def proc(n):
  5.     arquivo = open('coluna_test.dat', 'r')
  6.     geral = []
  7.     DH = []
  8.     SL = []
  9.     NO = []
  10.     global porcentagem
  11.     global cporcent
  12.     global k
  13.     for i in arquivo:
  14.         info = i.split(' ')
  15.         contagem = 0
  16.         x = []
  17.         dist = []
  18.         for i in info:
  19.             if contagem <= 5:
  20.                 i = float(i)
  21.                 x.append(i)
  22.                 if contagem == 5:
  23.                     for j in range(6):
  24.                         n=(usuario[j]-x[j])**2
  25.                         dist.append(n)
  26.                     n1=0
  27.                     n2=0
  28.                     for x in dist:
  29.                         n1+=x
  30.                     n2=n1**(1/2)
  31.                     geral.append(n2)
  32.             if contagem == 6:
  33.                 if (i == 'DH\n'):
  34.                     DH.append(n2)
  35.                 elif (i == 'SL\n'):
  36.                     SL.append(n2)
  37.                 elif (i == 'NO\n'):
  38.                     NO.append(n2)
  39.             contagem += 1
  40.     geral = sorted(geral)
  41.     DH = sorted(DH)
  42.     SL = sorted(SL)
  43.     NO = sorted(NO)
  44.     SIDH = 0
  45.     SISL = 0
  46.     SINO = 0
  47.  
  48.     while(k-1 >= len(geral)):
  49.         print('k extrapola o o número de amostras')
  50.         k=int(input('Valores de k na checagem\n'))
  51.  
  52.     for i in range(k):
  53.         if geral[i] in DH:
  54.             SIDH += 1
  55.         elif geral[i] in SL:
  56.               SISL += 1
  57.         elif geral[i] in NO:
  58.             SINO += 1
  59.     check2=[]
  60.     if SIDH >= SISL:
  61.         if SIDH>=SINO:
  62.             check2.append('DH\n')
  63.     if SISL >= SIDH:
  64.         if SISL>= SINO:
  65.             check2.append('SL\n')
  66.     if SINO >= SIDH:
  67.         if SINO>=SISL:
  68.             check2.append('NO\n')
  69.  
  70.     provacheck=[]
  71.     provacheck.append(random.choice(check2))
  72.  
  73.     if escolha <= 2:
  74.         print('Os dados da paciente inseridos, mostram que ele(a) é :',random.choice(provacheck))
  75.     if escolha==3:
  76.         if usuario[6] in provacheck:
  77.             porcentagem+=1
  78.         cporcent += 1
  79.     arquivo.close()
  80.  
  81. escolha = 0
  82. while(escolha!=4):
  83.     k=0
  84.     print('1-Usuario da informações em um única linha\n2-Usuario  da informações de cada vez\n3-Calibragem\n4-Sair\n\n\nOBS:\nDH = Hérnia de Disco\nSL = Espondilolistese\nNO = Normal\n')
  85.     escolha=int(input('Digite a opção\n'))
  86.  
  87.     if(escolha==1):
  88.         usuario = []
  89.         x=input('Insira as informações do paciente\n')
  90.         x=x.split(' ')
  91.         k=int(input('Valores de k na checagem\n'))
  92.         for i in x:
  93.             a=float(i)
  94.             usuario.append(a)
  95.         proc(k)
  96.     if(escolha==2):
  97.         usuario = []
  98.         k=int(input('Valores de k na checagem\n'))
  99.         for i in range(6):
  100.             a = float(input('Insira as informações do paciente :\n'))
  101.             usuario.append(a)
  102.         proc(k)
  103.     if(escolha==3):
  104.         porcentagem = 0
  105.         cporcent = 0
  106.         tamanho=0
  107.         nome=input('diga o nome do arquivo\n')
  108.         arquivo1 = open(nome,'r')
  109.         k=int(input('Valores de k na checagem\n'))
  110.         for i in arquivo1:
  111.             info = i.split(' ')
  112.             contagem = 0
  113.             usuario = []
  114.             tamanho+=1
  115.             for i in info:
  116.                 if contagem <= 5:
  117.                     i = float(i)
  118.                     usuario.append(i)
  119.                 if contagem == 6:
  120.                     usuario.append(i)
  121.                     proc(k)
  122.                 contagem += 1
  123.         if tamanho==cporcent:
  124.             porcent = porcentagem * 100 / cporcent
  125.             print(f'A taxa de acerto foi de {porcent}%')
  126.         arquivo1.close()
  127.     if(escolha==4):
  128.         sleep(1)
  129.         print('O programa será encerrado, até a proxima.')
  130.         sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement