sentences

py

School

Brigham Young University, Idaho *

*We aren’t endorsed by this school

Course

111

Subject

Computer Science

Date

Feb 20, 2024

Type

py

Pages

4

Uploaded by CaptainMaskPelican29

Report
import random def main(): quantity_1 = 1 quantity_2 = 2 tense = ["past", "present", "future"] counter = 0 sentences = [1, 2, 3] # for single sentences for i in sentences: determiner = get_determiner(quantity_1) noun = get_noun(quantity_1) verb = get_verb(quantity_1, tense[counter]) prep_phrase = get_prepositional_phrase(quantity_1) sentence = (f"{determiner.capitalize()} {noun} {verb} {prep_phrase}") print(sentence) i += 1 counter += 1 counter = 0 # for plural sentences for j in sentences: determiner = get_determiner(quantity_2) noun = get_noun(quantity_2) verb = get_verb(quantity_2, tense[counter]) prep_phrase = get_prepositional_phrase(quantity_2) sentence = (f"{determiner.capitalize()} {noun} {verb} {prep_phrase}") print(sentence) j += 1 counter += 1 def get_determiner(quantity): """Return a randomly chosen determiner. A determiner is a word like "the", "a", "one", "some", "many". If quantity == 1, this function will return either "a", "one", or "the". Otherwise this function will return either "some", "many", or "the". Parameter quantity: an integer. If quantity == 1, this function will return a determiner for a single noun. Otherwise this function will return a determiner for a plural noun. Return: a randomly chosen determiner. """ if quantity == 1: words = ["a", "one", "the"] else: words = ["some", "many", "the"] # Randomly choose and return a determiner. word = random.choice(words) # print(word) return word
def get_noun(quantity): """Return a randomly chosen noun. If quantity == 1, this function will return one of these ten single nouns: "bird", "boy", "car", "cat", "child", "dog", "girl", "man", "rabbit", "woman" Otherwise, this function will return one of these ten plural nouns: "birds", "boys", "cars", "cats", "children", "dogs", "girls", "men", "rabbits", "women" Parameter quantity: an integer that determines if the returned noun is single or plural. Return: a randomly chosen noun. """ if quantity == 1: words = ["bird", "boy", "car", "cat", "child", "dog", "girl", "man", "rabbit", "woman"] else: words = ["birds", "boys", "cars", "cats", "children", "dogs", "girls", "men", "rabbits", "women"] word = random.choice(words) # print(word) return word # get_noun(2) def get_verb(quantity, tense): """Return a randomly chosen verb. If tense is "past", this function will return one of these ten verbs: "drank", "ate", "grew", "laughed", "thought", "ran", "slept", "talked", "walked", "wrote" If tense is "present" and quantity is 1, this function will return one of these ten verbs: "drinks", "eats", "grows", "laughs", "thinks", "runs", "sleeps", "talks", "walks", "writes" If tense is "present" and quantity is NOT 1, this function will return one of these ten verbs: "drink", "eat", "grow", "laugh", "think", "run", "sleep", "talk", "walk", "write" If tense is "future", this function will return one of these ten verbs: "will drink", "will eat", "will grow", "will laugh", "will think", "will run", "will sleep", "will talk", "will walk", "will write" Parameters quantity: an integer that determines if the returned verb is single or plural. tense: a string that determines the verb conjugation, either "past", "present" or "future". Return: a randomly chosen verb. """ if tense == "past": verbs = ["drank", "ate", "grew", "laughed", "thought",
"ran", "slept", "talked", "walked", "wrote"] elif tense == "present" and quantity == 1: verbs = ["drinks", "eats", "grows", "laughs", "thinks", "runs", "sleeps", "talks", "walks", "writes"] elif tense == "present" and quantity != 1: verbs = ["drink", "eat", "grow", "laugh", "think", "run", "sleep", "talk", "walk", "write"] elif tense == "future": verbs = ["will drink", "will eat", "will grow", "will laugh", "will think", "will run", "will sleep", "will talk", "will walk", "will write"] verb = random.choice(verbs) # print(verb) return verb def get_preposition(): """Return a randomly chosen preposition from this list of prepositions: "about", "above", "across", "after", "along", "around", "at", "before", "behind", "below", "beyond", "by", "despite", "except", "for", "from", "in", "into", "near", "of", "off", "on", "onto", "out", "over", "past", "to", "under", "with", "without" Return: a randomly chosen preposition. """ prepositions = ["about", "above", "across", "after", "along", "around", "at", "before", "behind", "below", "beyond", "by", "despite", "except", "for", "from", "in", "into", "near", "of", "off", "on", "onto", "out", "over", "past", "to", "under", "with", "without"] # choose a random preposition from the list preposition = random.choice(prepositions) return preposition def get_prepositional_phrase(quantity): """Build and return a prepositional phrase composed of three words: a preposition, a determiner, and a noun by calling the get_preposition, get_determiner, and get_noun functions. Parameter quantity: an integer that determines if the determiner and noun in the prepositional phrase returned from this function are single or pluaral. Return: a prepositional phrase. """ preposition = get_preposition() determiner = get_determiner(quantity) noun = get_noun(quantity) prep_phrase = (f"{preposition} {determiner} {noun}.")
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
return prep_phrase main()