1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Python ValueError: float: Argument: . is not number on line 12

Discussão em 'Python' iniciado por Stack, Outubro 7, 2024 às 01:52.

  1. Stack

    Stack Membro Participativo

    Ok, so I'm new to python and I'm currently taking the python for everybody course (py4e).

    Our lesson 7.2 assignment is to do the following:


    7.2 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.

    I can't figure it out. I keep getting this error

    ValueError: float: Argument: . is not number on line 12


    when I run this code (see screenshot): https://gyazo.com/a61768894299970692155c819509db54 Line 12 which is num = float(balue) + float(num) keeps acting up. When I remove the float from balue then I get another which says


    "TypeError: cannot concatenate 'str' and 'float' objects on line 12".

    Can arguments be converted into floats or is it only a string? That might be the problem but I don't know if it's true and even if it is I don't know how to fix my code after that.

    Continue reading...

Compartilhe esta Página