+ 1
Word Chain
#my program a = input("Word: ").lower() b = input('Word: ').lower() while a and b: if a[-1] != b[0]: print("Invalid word") a = input('Word: ') b = input('Word: ') if a[0] != b[-1]: print("Invalid word") b = input('Word: ') ========================
6 Antworten
0
a = input("Word: ").lower()
b = a[0]
while a:
if a[0] == b:
b = a[-1]
else:
print("Invalid word")
a = input("Word: ").lower()
+ 1
Please add a brief description of the problem.
+ 1
Word Chain is word game where players take turns saying words that start with the last letter of the previous word. You might have played this game on long car trips.
Write a program to help you play word chain. Your program should read in words until a blank line is entered. It should print out Invalid word if a word is not a valid play. Your program should work for upper case and lower case words.
Here is an example:
Invalid word
Word: carrot
Word: tomato
Word: orange
Word: mandarin
Invalid word
Word: eggplant
Word:
Notice that the word mandarin is rejected because it doesn't start with the letter e from the previous word: orange. The next word still needs to start with the letter e (from orange), rather than n (from the end of the invalid word, mandarin).
Here is another example:
Word: tomato
Word: okra
Word: asparagus
Word: seaweed
Word: cake
Invalid word
Word: dried apricots
Word: cake
Invalid word
Word:
Here's one last example. Don't forget it should work regardless of case!
Word: Australia
Word: Antartic
Word: Canada
Word: England
Invalid word
Word: Denmark
Invalid word
Word:
+ 1
Thank so much Diego for help
0
Testing the first example from the question. Your submission did not produce the correct output.
Your program output:
Word: carrot
Word: tomato
Word: orange
Word: mandarin
Invalid word
Word: eggplant
Invalid word
Word:
when it was meant to output:
Word: carrot
Word: tomato
Word: orange
Word: mandarin
Invalid word
Word: eggplant
Word: