Having some issues, pls halp - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Having some issues, pls halp (/thread-2660.html) |
Having some issues, pls halp - Bidgey225 - Apr-01-2017 So I'm taking a course, and I can't quite see what I'm doing wrong with this program. [Image: mb2zobw.png] Moderator snippsat: Post code in code tag look at BBcode help Sorry, here's a more readable code block: fishy = "Call me Ishmael. Some years ago - never mind how long precisely - \ having little or no money in my purse, and nothing particular to interest me on \ shore, I thought I would sail about a little and see the watery part of the \ world. It is a way I have of driving off the spleen and regulating the \ circulation. Whenever I find myself growing grim about the mouth; whenever it \ is a damp, drizzly November in my soul; whenever I find myself involuntarily \ pausing before coffin warehouses, and bringing up the rear of every funeral I \ meet; and especially whenever my hypos get such an upper hand of me, that it \ requires a strong moral principle to prevent me from deliberately stepping into\ the street, and methodically knocking people's hats off - then, I account it \ high time to get to sea as soon as I can. This is my substitute for pistol and\ ball. With a philosophical flourish Cato throws himself upon his sword; I \ quietly take to the ship. There is nothing surprising in this. If they but \ knew it, almost all men in their degree, some time or other, cherish very \ nearly the same feelings towards the ocean with me." ishy = fishy.split() #in the first paragraph of moby dick, this function is designed to take an input #of a word, and at every point where it appears in the text, calculate the average #length of all the words that precede it every time it appears def prevword_ave_len(word): i = 0 curr_list = [] if ishy[0] == word: curr_list.append(len('')) return curr_list[0] elif word in ishy: for i in range(0,len(ishy)): if ishy[i] == word: curr_list.append(len(ishy[i-1])) i+=1 s = 0 for n in curr_list: s = s+n ave = '%.1f' % (s/len(curr_list)) return float(ave) else: return False print(prevword_ave_len('Call')) EDIT: don't worry, all solved RE: Having some issues, pls halp - metulburr - Apr-01-2017 (Apr-01-2017, 12:13 AM)Bidgey225 Wrote: EDIT: don't worry, all solvedThen please post your solution RE: Having some issues, pls halp - Bidgey225 - Apr-01-2017 Ok so the reason i was failing was a hidden input that shouldn't have been given to the program, I told my prof. and he has removed the typo from his testing set. That was it. |