TypeError for definied variable in python
<p>I'm trying to make a music player that allows a song to be put into the shell and is then played however, I'm having an issue with a type error in <code>class Notes():</code> and I can't figure out why.</p>

<pre><code>import winsound
import time

length = 125

class Notes():
    def processNote(note):
        if(note == 'C'):return Notes.processNote(262)
        if(note == 'D'):return Notes.processNote(294)
        if(note == 'D5'):return Notes.processNote(587)
        if(note == 'A'):return Notes.processNote(440)
        if(note == 'Ab'):return Notes.processNote(415)
        if(note == 'G'):return Notes.processNote(392)
        if(note == 'F'):return Notes.processNote(349)
        if(note == 'B'):return Notes.processNote(247)
        if(note == 'Bb'):return Notes.processNote(233)
song = "CCCCCCCCCCCD"
noteList = list(song)
print(noteList)

for note in noteList:
    print("Doing ", note)
    frequency = Notes.processNote(note)
    winsound.Beep(frequency, length)
</code></pre>

<p>The error: </p>

<pre><code>Traceback (most recent call last):
  File "C:\Python\Tester.py", line 27, in &lt;module&gt;
    winsound.Beep(frequency, length)
TypeError: an integer is required (got type NoneType)
</code></pre>

<p>Currently, the function <code>processNote()</code> returns <code>None</code> for any valid input, because you are calling it twice instead of just returning the value. It may be helpful to look at how your code will be processed to understand why this happens:</p>

<p>Imagine <code>processNote()</code> is called with the note value <code>"C"</code>. That will match the first <code>if</code> statement and it will return <strong>the result of calling <code>processNote()</code> with the value 262</strong>. Since there's no if statement that catches 262 in the <code>processNote()</code> function, it returns <code>None</code> (because this is the default for Python functions), so the <code>frequency</code> variable ends up being <code>None</code>.</p>

<p>You can solve this rather simply, by just returning the literal value:</p>

<pre><code>def processNote(note):
    if note == 'C':
        return 262
    ...
</code></pre>

python music typeerror