Print Highest, Average, Lowest score of a file
<p>I'm trying to print the highest, average, and lowest score of a file in python. But I keep getting error </p>

<pre><code>ValueError: invalid literal for int() with base 10.
</code></pre>

<p>My <em>results.txt</em> file looks like this:</p>

<pre><code>Johnny-8.65
Juan-9.12
Joseph-8.45
Stacey-7.81
Aideen-8.05
Zack-7.21
Aaron-8.31
</code></pre>

<p>And my code looks like this</p>

<pre><code>func1={}
with open('results.txt','r') as f:
    for line in f:
        name,value=line.split('-')
        value=float(value)
        if name in func1.keys():
           func1[name].append(value)
        else:
            func1[name]=[value]

#compute average: 
for name in func1:

    average=sum(func1[name])/len(func1[name])
    print("{} : {}".format(name,average))
</code></pre>

<p>Values that you provided in file are not <code>int</code> type.
For your approach you can use <code>float()</code>:</p>

<pre><code>value = float(value)
</code></pre>

<p>If you need to extract integer:</p>

<pre><code>s = "123"
num = int(s)
</code></pre>

<blockquote>
  <p>num = 123</p>
</blockquote>

<p>If you need to extract float number:</p>

<pre><code>s = "123.12"
num = float(s)
</code></pre>

<blockquote>
  <p>num = 123.12</p>
</blockquote>

<p>You can refer to documentation: <a href="https://docs.python.org/2/library/datatypes.html" rel="nofollow">Datatypes #1</a><a class='doc-link' href="http://stackoverflow.com/documentation/python/193/introduction-to-python#t=201609291554315469789">Datatypes #2</a></p>

<p>Also there is nice post about converting number datatypes in python: <a href="http://stackoverflow.com/questions/379906/parse-string-to-float-or-int">Parse String to Float or Int</a></p>

<p>How to get maximum key / value from dictionary refer to: <a href="http://stackoverflow.com/questions/268272/getting-key-with-maximum-value-in-dictionary">get max value</a><a href="http://stackoverflow.com/questions/3108042/get-max-key-in-dictionary">get max key</a></p>

<p>Also, read this article. It will help you to ask clearer questions.
<a href="http://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions">How do I ask and answer homework questions?</a></p>

python max average data-type-conversion min