-7

So basically I have my code here which prints a random Shakespearean insult through 3 lists. To submit this code, I have to print 20 insults and I know there is a faster way than writing the final print statement 20 times. This is probably remedial but I can't remember how to do it. Here's my code thanks guys:

import random

list1 = ["Artless", "Bawdy", "Bootless", "Churlish", "Clouted"]
list2 = ["Base-court", "Bat-fowling", "Beetle-headed", "Clay-brained" ]
list3 = ["Apple-john", "Baggage", "Bladder", "Boar-pig", "Coxcomb"]

def nurd1():
  return (random.choice(list1))

def nurd2():
   return (random.choice(list2))

def nurd3(): 
    return (random.choice(list3))

print ("Thou" + " " + nurd1() + " " +  nurd2() + " " + nurd3() )
TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97

3 Answers3

1
import random

words = [
["Thou"],
["Artless", "Bawdy", "Bootless", "Churlish", "Clouted"],
["Base-court", "Bat-fowling", "Beetle-headed", "Clay-brained" ],
["Apple-john", "Baggage", "Bladder", "Boar-pig", "Coxcomb"]
]

print(*(' '.join([random.choice(l) for l in words]) for r in range(20)), sep='\n')
TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97
0
from random import choice
list =[
 ["Artless", "Bawdy", "Bootless", "Churlish", "Clouted"],
 ["Base-court", "Bat-fowling", "Beetle-headed", "Clay-brained" ],
 ["Apple-john", "Baggage", "Bladder", "Boar-pig", "Coxcomb"]
]
for i in range(20):
    print '\nThou ',
    for j in range(len(list)):
        print choice(list[j]),
Max
  • 199
  • 1
  • 5
  • This is as basic as it gets. I hope this helps – Max Apr 24 '15 at 23:29
  • 1
    This shadows the built-in list type. The newline character is not necessary and I suspect OP is using Python 3.x in which print is a function instead of a statement. – Shashank Apr 24 '15 at 23:31
0

Simple while loop

loop = 0

while(loop <= 19):
    print ("Thou" + " " + nurd1() + " " +  nurd2() + " " + nurd3() )
    loop += 1

tho' it'll print 20 different lines!

AlphaOmega
  • 45
  • 2
  • 10