my children and I are messing with a random bedtime story generator. And apart from being amazed at how easy python is to use, we want to generate a random name for our protagonist, but for them to keep the same name throughout the story.
import random
names= ["Tim", "Ju Ju", "Legface", "Dusty", "Smudger"]
thing = ["princess", "elf", "fairy", "mermaid", "shoe maker"]
count = 0
while (count < 1):
print "Once upon a time there was a ",
print(random.choice(thing)),
print "whose name was ",
print(random.choice(names)),
so if the random name turns out to be Tim, I would like to continue the story as
print $thevariablethatisTim
print "was a very happy man"
I realise this is a trivial thing, but I can't seem to get it right and we are having such a good laugh at bedtime with this.
Thanks in advance
Neil
name = random.choice(names)?!ifstatement to check whether yourandom.choiceisTim?