0

Hey all I just started learning about programming and this is problem I need to solve but I just can't get it: Get your computer to produce its 100 first utterances. These utterances are sequences of 1, 2, 3, or 4 random syllables sampled from the list:

[“ba”,”bi”,”bu”,”ga”,”gi”,”gu”].

You have to write a program that prints 100 random utterances of this type. For each utterances you have to select a random length (of 1, 2,3 or 4 syllables) for each utterance, plus randomly sample the chosen number of syllables from the set above.

1 Answers1

0

So there's no point just giving you code, or you won't learn anything, but here are some ingredients:

  1. You'll want a for loop that runs 100 times to give 100 utterances.
  2. Inside that loop, you need a random number from 1 to 4 (for the number of syllables). You could import the random module and use randint to get the number. Let's say you call this number n_syll. Also, initialize an empty string to hold your word.
  3. Then, still inside the original for loop, you need to make the actual word. Start another for loop that runs n_syll times. On each iteration, randomly select the syllable (see How to randomly select an item from a list?). Concatenate it with the word string.
  4. When you pop outside the inner loop, you should have a random word. Just print it!

This isn't the most elegant way to do it, but it'll get the job done.

If any of these steps are too hard, maybe run through the Codecademy Python tutorial to get familiar with the basics of the language.

Community
  • 1
  • 1
Dave Kielpinski
  • 1,152
  • 1
  • 9
  • 20