[Tutor] space between words printed

Mark Lawrence breamoreboy at yahoo.co.uk
Sun Nov 3 10:13:36 CET 2013


On 03/11/2013 03:18, Byron Ruffin wrote:
> The output generates a sentence made up of words chosen randomly from
> lists.  I am having trouble getting a space between each of the words.
> Should I be thinking about .split?  Here is the code (ignore indent
> errors as it was copied and pasted) Thank you:
>
> import random
>
> def wordList():
>
>      adj1 = ["Big",        "Small",  "Early",  "Late",    "Red",
> "Tall",    "Short"]
>      subj = ["politician", "man",    "woman",  "whale",   "company",
> "child",   "soldier"]
>      obj =  ["budget",     "money",  "box",    "gift",    "gun",
> "tank",    "drone"]
>      adj2 = ["hot",        "crazy",  "stupid", "fast",    "worthless",
> "awesome", "dirty"]
>      verb = ["spends",     "shoots", "evades", "pursues", "subverts",
> "passes",  "flirts"]
>
>      y = adj1[generate()], subj[generate()] + obj[generate()] +
> adj2[generate()] + verb[generate()]
>
>      return y
>
>
> def generate():
>      random0_6 = random.randint(0, 6)
>      return random0_6
>
>
> def main():
>
>      print (wordList(), ".", sep="")
>
>
> main()
>

Look very carefully at your assignment to y in wordList and you'll 
eventually answer your own question.

-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence



More information about the Tutor mailing list