我有一个名为newSong的文本字符串,其中包含两个instancevariabel(标题,艺术家),如下所示:
newSong =歌曲(“ Rum and Raybans”,“ Sean Kingston and Cher Lloyd”)
我有一个称为checkIfArtistExists(self,artist)的方法,我的任务是使用split,for循环和if语句。我必须拆分艺术家,所以如果艺术家的名字由肖恩,金斯顿,雪儿,劳埃德组成,它将返回true,否则返回false。
我收到assertError:
assert(not newSong.checkIfArtistExsists(“ Sadley”))#FalseAssertionError
对编程还是陌生的,我的逻辑不是很好。有人可以给我建议或提示吗?
类歌曲(对象):
def init(自己,小标题,艺术家):
#Instanse variabler
self._tittel = tittel
self._artist = artist
def CheckIfArtistExists(self,artist):
names = artist.split()
for n in names:
if n in artist:
return true
else:
return false
newSong =歌曲(“ Rum and Raybans”,“ Sean Kingston and Cher Lloyd”)
assert(newSong.CheckIfArtistExists(“ Sean Kingston and Cher Lloyd”))assert(不是newSong.CheckIfArtistExists(“” Sadley“”))#False
您正在针对自己而不是实例变量artist
测试_artist
参数。