Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
57
Task/Mad-Libs/Nanoquery/mad-libs.nanoquery
Normal file
57
Task/Mad-Libs/Nanoquery/mad-libs.nanoquery
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
def madlib(template)
|
||||
// loop through and find/remove all of the replacements
|
||||
replacements = {}
|
||||
ind = 0
|
||||
while ind < len(template)
|
||||
// check if we have found a replacement to perform
|
||||
if template[ind] = "<"
|
||||
// get the name of the replacement and add it to the list
|
||||
// if we haven't already encountered it
|
||||
ind += 1
|
||||
replace_name = ""
|
||||
while template[ind] != ">"
|
||||
replace_name += template[ind]
|
||||
ind += 1
|
||||
end while
|
||||
|
||||
if not replace_name in replacements
|
||||
replacements.append(replace_name)
|
||||
end if
|
||||
ind += 1
|
||||
else
|
||||
ind += 1
|
||||
end if
|
||||
end while
|
||||
|
||||
// prompt the user for replacement values
|
||||
replacement_values = {}
|
||||
for phrase in replacements
|
||||
replacement_values.append(input("enter " + phrase + ": "))
|
||||
end for
|
||||
println
|
||||
|
||||
// make replacements and output the story
|
||||
ind = 0
|
||||
while ind < len(template)
|
||||
// check if we have found a replacement to perform
|
||||
if template[ind] = "<"
|
||||
// get the name of the replacement
|
||||
ind += 1
|
||||
replace_name = ""
|
||||
while template[ind] != ">"
|
||||
replace_name += template[ind]
|
||||
ind += 1
|
||||
end while
|
||||
|
||||
// output the replacement
|
||||
print replacement_values[replacements[replace_name]]
|
||||
ind += 1
|
||||
else
|
||||
print template[ind]
|
||||
ind += 1
|
||||
end if
|
||||
end while
|
||||
end madlib
|
||||
|
||||
madlib("<name> went for a walk in the park. <he or she> " + \
|
||||
"found a <noun>. <name> decided to take it home.")
|
||||
Loading…
Add table
Add a link
Reference in a new issue