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 class Notes(): and I can't figure out why.
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)
The error:
Traceback (most recent call last):
File "C:\Python\Tester.py", line 27, in <module>
winsound.Beep(frequency, length)
TypeError: an integer is required (got type NoneType)
return 262and so on; currently you are calling your function twice, and the second time always returnsNonebecause you are passing it an integer your function only handles strings..processNotemethod returns None.