So I'm trying to count anhCrawler and return the number of characters with and without spaces alone with the position of "DEATH STAR" and return it in theReport. I can't get the numbers to count correctly either. Please help!
anhCrawler = """Episode IV, A NEW HOPE. It is a period of civil war. \ Rebel spaceships, striking from a hidden base, have won their first \ victory against the evil Galactic Empire. During the battle, Rebel \ spies managed to steal secret plans to the Empire's ultimate weapon, \ the DEATH STAR, an armored space station with enough power to destroy \ an entire planet. Pursued by the Empire's sinister agents, Princess Leia\ races home aboard her starship, custodian of the stolen plans that can \ save her people and restore freedom to the galaxy.""" theReport = """ This text contains {0} characters ({1} if you ignore spaces). There are approximately {2} words in the text. The phrase DEATH STAR occurs and starts at position {3}. """ def analyzeCrawler(thetext): numchars = 0 nospacechars = 0 numspacechars = 0 anhCrawler = thetext word = anhCrawler.split() for char in word: numchars = word[numchars] if numchars == " ": numspacechars += 1 anhCrawler = re.split(" ", anhCrawler) for char in anhCrawler: nospacechars += 1 numwords = len(anhCrawler) pos = thetext.find("DEATH STAR") char_len = len("DEATH STAR") ds = thetext[261:271] dspos = "[261:271]" return theReport.format(numchars, nospacechars, numwords, dspos) print analyzeCrawler(theReport)
I can't get the numbers to count correctly either.So what are the expected results and what are you getting now?