What else do I need for CodeHS 8.3.8: Word Ladder?

8.4.4: how many names?
8.1 10 coordinate pairs
8.3.7: exclamat!on po!nts
8.4.5: five numbers
codehs 8.3 6 answers
exercise 6.2 14 word ladder
8.4.12: librarian, part 2
codehs 8.3.6 owls

This is what I am supposed to do:

Your friend wants to try to make a word ladder! This is a list of words where each word has a one-letter difference from the word before it. Here’s an example:

cat
cot
cog
log

Write a program to help your friend. It should do the following:

  • Ask your friend for an initial word.
  • Repeatedly ask them for an index and a letter.
  • You should replace the letter at the index they provided with the letter they enter.
  • You should then print the new word.
  • Stop asking for input when the user enters -1 for the index.

Here’s what should be happening behind the scenes:

  • You should have a function, get_index, that repeatedly asks the user for an index until they enter a valid integer that is within the acceptable range of indices for the initial string. (If they enter a number out of range, you should output invalid index.)
  • You should have another function, get_letter, that repeatedly asks the user for a letter until they enter exactly one lowercase letter. (If they enter more than one character, you should output Must be exactly one character!. If they enter a capital letter, you should output Character must be a lowercase letter!.)
  • You should store a list version of the current word in a variable. This is what you should update each time the user swaps out a new letter.
  • Each time you have to print the current word, print the string version of the list you are keeping in your variable.

Here’s what an example run of your program might look like:

Enter a word: cat
Enter an index (-1 to quit): 1
Enter a letter: o
cot
Enter an index (-1 to quit): 2
Enter a letter: g
cog
Enter an index (-1 to quit): 5
Invalid index
Enter an index (-1 to quit): -3
Invalid index
Enter an index (-1 to quit): 0
Enter a letter: L
Character must be a lowercase letter!
Enter a letter: l
log
Enter an index (-1 to quit): -1

This is my code right now:

word = input("Enter a word: ")
for i in range():
    get_index = int(input("Enter an index (-1 to quit): "))
    if get_index < -1:
        print "Invalid index"
    elif get_index > 3:
        print "Invalid index"
    else:
        letter = input("Enter a letter: ")
        word = word[:get_index] + letter + word[get_index + 1:]
        print word

So I'm not entirely sure how to make an if/else statement for all capital letters and only allow one letter. I'm also not sure about what I need to put in my for loop to make it end when I enter -1.

Word Ladder should keep running and keep printing the results until the index is -1. Here is a quick solution.


play word ladder
def get_index(word):
    while True:
        try:
            pos = int(input("Enter an index: "))
            if pos == -1:
                return pos
            elif pos >= len(word):
                print "invalid index"
            elif pos <= -1:
                print "invalid index"
            else:
                return pos
        except ValueError:
            print "invalid index"
            
def get_letter():
    
    while True:
        
        char = str(input("Enter a letter: "))
    
        if char.islower() and len(char)==1:
            return char
    
        elif  not char.islower():  
            print "Character must be a lowercase letter!"
  
        elif len(char) > 1:
            print "Must be exactly one character!"

def word_ladder(word):
    
    while True:
        pos = get_index(word)
        if pos == -1:
            return
        else:
            char=get_letter() 
            
            word = list(word)
            word[pos] = char
            word = ("").join(word)
            print word

word = input("Enter a word: ") 

word_ladder(word)

Program for CodeHS 8.3.8: Word Ladder in Python 3, Stop asking for input when the user enters -1 for the index. What else do I need for CodeHS 8.3.8: Word Ladder? 0. Skipping print but continuing program. Hot Network Questions

init_input = input("Enter word: ")

def get_index():
    while True:
        try:
            index = int(input("Index (-1 to quit): "))
        except ValueError:
            print("This must be a number!")
            continue
        if index < 0 and index != -1 or index > len(init_input)-1:
            print("Invalid Index!")
        else:
            return(index)


def get_letter():
    while True:
        letter = input("Enter a letter: ")
        if letter != letter.lower():
            print("Character must be a lowercase letter!")
        elif len(letter) != 1:
            print("Must be exactly one letter!")
        else:
            return(letter)

while True:
    init_input = list(init_input)
    index = get_index()
    if index == -1:
        break
    char = get_letter()
    init_input[index] = char
    print(''.join(init_input))

Word-Ladder solver in Python 3Python program to find a word , While your code seems to work, the next step should be separating the different responsibilities of your code. As far as I can see, there are three: You have to ask � This part is a word ladder. A word ladder is when you move from one word to another with only changing 1 letter, so for example if you wanted to move from dog to bog, then you are just altering one letter (the “d” to a “b”), but if you are going from code -> data, then you would have to go through a couple of changes to get to the end word.

word = str(input("your word: "))
print(word)
run = True
while run:
    #ensure he enters a number not letter 
    while True:
        try:
            index = int(input("enter index: "))
            break
        except:
            print("please enter a number not letter")
    #check to see if the index is within the provided word lenght
    while -1 < index < len(word):
        #doesn't matter if he enters an uppercase letter becasue the lowermethod will turn it to lowercase
        letter = str(input("enter letter: ")).lower()
        #check to ensure he provides one letter only
        while len(letter) == 1:
            word = word[:index] + letter + word[index + 1 :]
            print(word)
            break
        else:
            print("enter one letter")
        break
    else:
        #quits if the index is -1
        if index == -1:
            run = False
        #if the index not -1 not in the length of the word ,prints invalid
        else:
            print("invalid index")

edited the mistakes i made and tested it, works fine now. expected output:

your word: cat
cat
enter index: 1
enter letter: o
cot
enter index: -3
invalid index
enter index: 5
invalid index
enter index: -1

8.3.8: Word Ladder Code HS : codehs, for CodeHS 8.3.8: Word Ladder in Python 3Countdown - word a chain of other words to link the two, in which two adjacent words (that is, words in I just didn't have a good enough understanding of the term "tree" so the� Each transformed word must exist in the word list. Note: Return 0 if there is no such transformation sequence. All words have the same length. All words contain only lowercase alphabetic characters. You may assume no duplicates in the word list. You may assume beginWord and endWord are non-empty and are not the same. Example 1:

Python practice 82: Word Ladder – statyang, 8.3.8: Word Ladder Code HS. This is what I have but seems to be wrong, anyone knows where the mistake is? def get_index(a): x = 0 while(true): try: x� In a word ladder puzzle you must make the change occur gradually by changing one letter at a time. At each step you must transform one word into another word, you are not allowed to transform a word into a non-word. The word ladder puzzle was invented in 1878 by Lewis Carroll, the author of Alice in Wonderland. The following sequence of words

Word Ladder – Coding Friends, All words have the same length. •All words contain only lowercase alphabetic characters. Analysis: For this question, it is not easy to get your solution passed test. I� Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

https://github.com/Th3-H4xx0r/CodeHs-Answers-Unit8, So what we need to do is to have a way of finding another word with just changing one of the letters within the linking words, so, if we alter each� CodeHS has everything you need to teach computer science at your school, including web-based curriculum, teacher tools, administrator insights, and professional development. The students say the class is "fun, fun, fun" and that the class period is too short.

Comments
  • Have you tried running this code? It won't work
  • Exactly. There's an error because I need something in my for loop, but I don't know what it is.
  • "Stop asking for input when the user enters -1 for the index" - the user may, in theory, never enter -1, but range can only generate a finite amount of numbers.
  • So I know that I need to put break in the code when the user enters -1, but where does it need to be? I'm also wondering if I need a while loop instead of a for loop.
  • Yes, you need a while loop. "Stop asking for input when the user enters -1 for the index" - so, you need the break right after you know the user entered -1.