Python Forum
Having some issues, pls halp
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having some issues, pls halp
#1
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
Reply
#2
(Apr-01-2017, 12:13 AM)Bidgey225 Wrote: EDIT: don't worry, all solved
Then please post your solution
Recommended Tutorials:
Reply
#3
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020