I found when I used this code the program accepted it (code 1 below). The output to code 1 is seen as:
(base) Valentín Python_Programming_MOOC $ python3 construction.py
Please type in a word: hello hi
Please type in a word: sup sup
Please type in a word:
Notice that if you input to nonidentical words in the beginning, and then two identical the program still expects it. I think this should also be tested rather than just "hello" "world world" but something like "hi hello" "world world". I fixed this with code 2.
CODE 1
words = ''
word_list = []
word_list_dup = []
while True:
word = input("Please type in a word: ")
if word != 'end':
if " " in word:
# print('There is a space:')
word_list_dup.append(word.split())
# print(f'words with space: {word_list_dup}')
word_list.extend(word_list_dup[0][::])
# print(" ".join(word_list))
# print('printing here 1')
if word_list[-1] == word_list[-2]:
# print('printing here 1')
print(" ".join(word_list[:-1]))
break
elif " " not in word:
words += word + ' '
word_list.append(word)
# print('printing here 2')
# print(" ".join(word_list))
if len(word_list) >= 2:
if word_list[-1] == word_list[-2]:
# print('printing here 3')
print(" ".join(word_list[:-1]))
break
else:
# print('printing here 4')
# print(" ".join(word_list))
continue
elif word == 'end':
print(" ".join(word_list))
# print('printing here end')
break
CODE 2
words = ''
word_list = []
word_list_dup = []
while True:
word = input("Please type in a word: ")
if word != 'end':
if " " in word:
new_words = word.split()
word_list.extend(new_words)
# print('printing here 1')
# print(f'word list: {word_list}')
# print(f'length of word list: {len(word_list)}')
if len(word_list) >= 2: # new line here
if word_list[-1] == word_list[-2]:
# print('printing here 2')
print(" ".join(word_list[:-1]))
break
elif " " not in word:
words += word + ' '
word_list.append(word)
# print('printing here 3')
# print(" ".join(word_list))
if len(word_list) >= 2:
if word_list[-1] == word_list[-2]:
# print('printing here 4')
print(" ".join(word_list[:-1]))
break
else:
# print('printing here 5')
# print(" ".join(word_list))
continue
elif word == 'end':
print(" ".join(word_list))
# print('printing here end')
break
I found when I used this code the program accepted it (code 1 below). The output to code 1 is seen as:
(base) Valentín Python_Programming_MOOC $ python3 construction.py
Please type in a word: hello hi
Please type in a word: sup sup
Please type in a word:
Notice that if you input to nonidentical words in the beginning, and then two identical the program still expects it. I think this should also be tested rather than just "hello" "world world" but something like "hi hello" "world world". I fixed this with code 2.
CODE 1
CODE 2