Hii!
I'm new to python and I don't understand how to code this assignment. Here are the instructions:
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 reply 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 reply Must be exactly one character!. If they enter a capital letter, you should reply 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 I have:
question = input("Please enter an initial word: ")
list_question = list(question)
def get_index:
for i in range:
ask_index = input("Please enter an index(-1 to quit): ")
if ask_index < -1 or ask_index > len(list_question):
print("invalid index")
else:
return ask_index
def get_letter:
for i in range:
ask_letter = input("Please enter a letter: ")
if len(ask_letter) > 1:
print("Must be exactly one character!")
if ask_letter.isupper():
print("Character must be a lowercase letter!")
else:
return ask_letter
I don't know how to do the rest of it. Help!