Python Forum
Stranger in our midst
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stranger in our midst
#1
Exercise is as following:
Find the outsider that is hidden in a list where one word is repeated over and over.
Input
A list of n words (n>0) — each on a separate line — ending with a line that only contains the word stop. Of all n words, at least one is different from the others.
Output
If all words are equal, the text there is no outsider should appear. Otherwise, the text the outsider is "word" should appear. The word in italics is the word that is different from the rest. If the list consists of 2 different words, it is impossible to determine which of both is wrong. In this case, the text outsider can't be determined should appear.
Example
Input:
Paraguay
Egypt
Paraguay
Paraguay
Paraguay
Paraguay
Paraguay
stop
Output:

the outsider is "Egypt"
So I'm already stuck at the first half of the problem namely adding words to the list line per line. This is what I've tried:

words=[]
new_word=str(input("Enter a word\n"))
if new_word != "stop":
    words.append(new_word)
#So this code immediately stops after the new word is added, what is normal because it isn't a loop. So i tried to replace if with while so it would keep adding words till the word is stop but than the program won't even run. 
print(words)
Reply


Messages In This Thread
Stranger in our midst - by tfak - Mar-22-2021, 09:16 AM
RE: Stranger in our midst - by GOTO10 - Mar-22-2021, 11:40 AM
RE: Stranger in our midst - by Serafim - Mar-22-2021, 01:21 PM
RE: Stranger in our midst - by deanhystad - Mar-22-2021, 03:04 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020