Skip to main content
0 online
C
chuckthecloneOG 2002

word = ["h","e","l","l","o"]
len1 = len(word)
blanks = ["_","_","_","_","_"]
print ''.join(word)
print ' '.join(blanks)
def lb():
guess = raw_input("Choose a letter. ")
count1 = 0
correct = 0
while count1 <= len1:
if guess == word[count1]:
blanks[count1] = guess
correct = 1
count1 = count1 + 1
lb()
if correct == 1: lb()
else: print "You lose"
print ''.join(word)
print ' '.join(blanks)

alright i wrote that to see if somethings would work the way i wanted them to. they didn't. when i run it i get an error. this is what it looks like.

hello
_ _ _ _ _
Choose a letter. h

Traceback (most recent call last):
File "C:\python2.4\hangman1.py", line 15, in -toplevel-
lb()
File "C:\python2.4\hangman1.py", line 11, in lb
if guess == word[count1]:
IndexError: list index out of range

it says the list index is out of range on line 11. that part should work. i've tested it outside of that program and it works. guess should equal h. count1 should equal 0. it should check to see if the first index in word is h. don't know whats wrong. i might just rewrite it using a for statement.

C
chuckthecloneOG 2002

i copy and pasted from another place so i don't know how or why it looks the way it does...

yay yayOG 2004

while count1 <= len1 is a classical 'off by one' logical error

Subscript out of range means you are trying to access the array variable "word" out of it's original range you declared it for.

length of word = 5
word[0] = h
word[1] = e
......
word[4] = o
word[5] = subscript error

C
chuckthecloneOG 2002

thanks for the help. i saw that 2 days after i posted.

Welcome Back to eZabel

It's been a while. Here's what's new.

eZabel Lore

A complete history of our community — stats, Hall of Fame, legendary threads, and more.

View the Lore →

Everything Preserved

All 225,969 pieces of content from 2000–2014 are here — forums, messages, journals, photos, polls, and events.

💎

Gems

Spot something you love — a legendary comment, a classic thread, a great photo? Log in and click the diamond icon to mark it as a Gem. Add a note about why it's special. The best stuff surfaces on the Gems page.