Jump to content

guiromero

Membros
  • Contagem de Conteúdo

    1
  • Ingressou

  • Última visita

Informações Pessoais

  • Cidade
    são Paulo
  • Estado
    São Paulo (SP)

Clientes & Parceiros

  • Você é um cliente TecnoSpeed?
    Não
  • Você é um parceiro da Casa do Desenvolvedor?
    Não

Conquistas de guiromero

0

Reputação na Comunidade

  1. Olá, Estou fazendo um exercício cujo enunciado é o seguinte: " Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form: X-DSPAM-Confidence: 0.8475 Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below. Do not use the sum() function or a variable named sum in your solution. You can download the sample data at http://www.py4e.com/code3/mbox-short.txt when you are testing below enter mbox-short.txt as the file name." A resposta deve ser: “Average spam confidence: 0.7507185185185187” O código que criei está abaixo: ................... fname = input("Enter file name: ") fh = open(fname) i=0 tot = 0 for line in fh: if not line.startswith("X-DSPAM-Confidence:"): continue v = (line[20:26]) value = float(v) i=i+1 tot = tot + value av = (float(tot/i)) print(av) ......................... A resposta que aparece é uma lista de valores médios acumulados. Quero extrair só o último valor (0.7507185185185187), como faço? Obrigado.
×
×
  • Create New...