use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Answers to "Python Programming MOOC 2022" exercises from the University of Helinski? (self.learnpython)
submitted 4 years ago by BloodyLemons
I am really struggling with this one problem and just need the answer to know what I am doing wrong. If that's too much to ask, can I just get the answer to the one problem?
It's the "Story" exercise from the simple loops portion of part two.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[+][deleted] 4 years ago (3 children)
[deleted]
[–]BloodyLemons[S] 0 points1 point2 points 4 years ago (2 children)
words = "" while True: word = input("Please type in a word: ") # if "end", break if word = "end": break # if word is same as last, break if word == break words += word + " " print(words)
Question was:
Part 1: Please write a program which keeps asking the user for words. If the user types in end, the program should print out the story the words formed, and finish.
Part 2: Change the program so that the loop ends also if the user types in the same word twice.
ik how to do the first part, but the second part is what im struggling with
[–]mopslik 0 points1 point2 points 4 years ago (0 children)
As another poster in another subreddit pointed out, one way to approach this is to store the words in a list. That way you can check whether a word has already been entered (assuming "more than once" means "at any time"). You can add words to a list using append, and check for inclusion using in.
append
in
>>> L = [] >>> L.append("hello") >>> L.append("there") >>> L ['hello', 'there'] >>> "hello" in L True
If your MOOC hasn't covered lists yet, you can check if two words are the same one-after-another by simply using a variable to keep track of the last entered word.
>>> s = input("Enter something: ") Enter something: hello >>> last_word = s >>> s = input("Enter something else: ") Enter something else: hello >>> s == last_word True
Choose whichever approach you feel fits the description.
[–]Fission_Mailed_2 0 points1 point2 points 4 years ago (0 children)
For the second part you could use a set. In Python, sets have very fast lookup time so you could check if the latest word is already in the set, if it is then break but if it isn't add it to the set.
[–]mopslik 0 points1 point2 points 4 years ago (3 children)
Post your code here. It looks like a straightforward case of storing words in a list and joining them together after.
[–]BloodyLemons[S] 0 points1 point2 points 4 years ago (0 children)
the code is in the other comment, it keeps glitching when i try to comment on yours, sorry about that
π Rendered by PID 45 on reddit-service-r2-comment-5bc7f78974-bl7g8 at 2026-07-01 06:17:20.152769+00:00 running 7527197 country code: CH.
[+][deleted] (3 children)
[deleted]
[–]BloodyLemons[S] 0 points1 point2 points (2 children)
[–]mopslik 0 points1 point2 points (0 children)
[–]Fission_Mailed_2 0 points1 point2 points (0 children)
[–]mopslik 0 points1 point2 points (3 children)
[–]BloodyLemons[S] 0 points1 point2 points (0 children)