Aug-31-2017, 12:32 AM
(This post was last modified: Aug-31-2017, 12:32 AM by defenderofthebit.)
http://anh.cs.luc.edu/handsonPythonTutorial/idle.html
a tutorial i am working from. it works similarly what i am trying to show, but not quite the same.
this is their example
a tutorial i am working from. it works similarly what i am trying to show, but not quite the same.
this is their example
#! /usr/bin/env python3 ''' String Substitution for a Mad Lib Adapted from code by Kirby Urner ''' storyFormat = ''' Once upon a time, deep in an ancient jungle, there lived a {animal}. This {animal} liked to eat {food}, but the jungle had very little {food} to offer. One day, an explorer found the {animal} and discovered it liked {food}. The explorer took the {animal} back to {city}, where it could eat as much {food} as it wanted. However, the {animal} became homesick, so the explorer brought it back to the jungle, leaving a large supply of {food}. The End ''' def tellStory(): userPicks = dict() addPick('animal', userPicks) addPick('food', userPicks) addPick('city', userPicks) story = storyFormat.format(**userPicks) print(story) def addPick(cue, dictionary): '''Prompt for a user response using the cue string, and place the cue-response pair in the dictionary. ''' prompt = 'Enter an example for ' + cue + ': ' response = input(prompt) dictionary[cue] = response tellStory() input('Press Enter to end the program.')this is my example
''' string substitution ''' #assinging the string storyFormat is the core text of our story. the #curly braces around certain words within the text are eventually going to be #chosen by the user and changed in the story by auto writing #their values into a dictionary, based on user input upon promt storyFormat = ''' So one day theres this {person} right? aaand this {person} love to eat {food}. and the {person} was broke in the {hood}. ya see {the man} was keeping the {person} down. so the {person} wanted to escape the {hood} and get back to the{wild} where he was free of {the man}. ''' #def is short for definition. In this case we are defining a series of strings #and variables which allow the strings to be altered later in the code def tellStory (): userPicks = dict() addPick('person' , userPicks) addPick('the man' , userPicks) addPick('hood' , userPicks) addPick('wild' , userPicks) story = storyFormat.format(**userPicks) print (story) #cue and dictionary in the definition addPick, are a tuple, where as tellStory #allows you to choose which tuple is used by leaving it blank def addPick(cue, dictionary): #prompt is created to know what to ask the user to input and then #adding response is the part that does the asking #to the prompts for hood,the man, person, and wild, #which will be added into the dictionary because of, def tellStory, above prompt = 'enter an example for ' + cue +': ' response = input(prompt) dictionary[cue] = response tellStory() input('Press Enter to end the program')mine is giving back a traceback error, can you help me label the rest of it so i can find the error? i have been comparing them, and tried multiple things. i am confused as to what is wrong with mine.
''' string substitution ''' #assinging the string storyFormat is the core text of our story. the #curly braces around certain words within the text are eventually going to be #chosen by the user and changed in the story by auto writing #their values into a dictionary, based on user input upon prompt storyFormat = ''' So one day theres this {person} right? aaand this {person} love to eat {food}. and the {person} was broke in the {hood}. ya see {the man} was keeping the {person} down. so the {person} wanted to escape the {hood} and get back to the{wild} where he was free of {the man}. ''' #def is short for definition. In this case we are defining a series of strings #and variables which allow the strings to be altered later in the code def tellStory (): userPicks = dict() #make sure you add a new pick option for every object in the string above, or you may have traceback error addPick('person' , userPicks) addPick('the man' , userPicks) addPick('hood' , userPicks) addPick('wild' , userPicks) addPick('food' , userPicks) story = storyFormat.format(**userPicks) print (story) #cue and dictionary in the definition addPick, are a tuple, where as tellStory #allows you to choose which tuple is used by leaving it blank def addPick(cue, dictionary): #prompt is created to know what to ask the user to input and then #adding response is the part that does the asking #to the prompts for hood,the man, person, and wild, #which will be added into the dictionary because of, def tellStory, above prompt = 'enter an example for ' + cue +': ' response = input(prompt) dictionary[cue] = response tellStory()input('Press Enter to end the program')