Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Modifying code
#1
Is there a way to modify this code for it to search for the sentences generated to:
— always start with capitalized words ("This is beautiful.", "You are a great programmer!", etc.);
— not start with a word that ends with a sentence-ending punctuation mark ("Okay.", "Nice.", "Good.", "Look!", "Jon!", etc.);
— always end with a sentence-ending punctuation mark like ., !, or ?;
— should not be shorter than 5 tokens.

My code:

sentence_count = 10
while sentence_count != 0:
    generated_sentence = []
    current_word = random.choice(text1)
    generated_sentence.append(current_word)
    count = 9
    while count != 0:
        next_word = Counter(head_tail[current_word]).most_common(1)[0][0]
        generated_sentence.append(next_word)
        current_word = next_word
        count -= 1
    print(" ".join(generated_sentence))
    sentence_count -= 1
Yoriz write Dec-12-2021, 08:40 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Modifying code - by cheburashka - Dec-12-2021, 07:14 PM
RE: Modifying code - by Kebap - Dec-13-2021, 01:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Modifying Lists RedSkeleton007 12 6,875 Nov-22-2017, 04:31 AM
Last Post: heiner55
  Assistance Modifying Code chuco61 2 3,502 Apr-30-2017, 03:35 PM
Last Post: michaelcollier
  win32 package: self-modifying source code??? Orthoducks 3 4,504 Jan-13-2017, 09:29 AM
Last Post: buran

Forum Jump:

User Panel Messages

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