Python Classroom image

Anil  Bist / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9|Last
Lessons:-INTRODUCTION

1.2. THE PYTHON INTERPRETER AND IDLE, PART I 8
explorer brought it back to the jungle, 16
leaving a large supply of {food}. 17
18
The End 19
""" 20
21
def tellStory(): 22
userPicks = dict() 23
addPick(’animal’, userPicks) 24
addPick(’food’, userPicks) 25
addPick(’city’, userPicks) 26
story = storyFormat.format(**userPicks) 27
print(story) 28
29
def addPick(cue, dictionary): 30
’’’Prompt for a user response using the cue string, 31
and place the cue-response pair in the dictionary. 32
’’’ 33
prompt = ’Enter an example for ’ + cue + ’: ’ 34
response = input(prompt) 35
dictionary[cue] = response 36
37
tellStory() 38
input("Press Enter to end the program.") 39
Line By Line Explanation
""" 1
String Substitution for a Mad Lib 2
Adapted from code by Kirby Urner 3
""" 4
1-4 There is multi-line text enclosed in triple quotes. Quoted text is called a string. A string at the
very beginning of a file like this is documentation for the file.
5,21,29,37 Blank lines are included for human readability to separate logical parts. The computer ignores
the blank lines.
storyFormat = """ 6
Once upon a time, deep in an ancient jungle, 7
there lived a {animal}. This {animal} 8
liked to eat {food}, but the jungle had 9
very little {food} to offer. One day, an 10
explorer found the {animal} and discovered 11
it liked {food}. The explorer took the 12
{animal} back to {city}, where it could 13
eat as much {food} as it wanted. However, 14
the {animal} became homesick, so the 15
explorer brought it back to the jungle, 16
leaving a large supply of {food}. 17
18
The End 19
""" 20
6 The equal sign tells the computer that this is an assignment statement. The computer will now
associate the value of the expression between the triple quotes, a multi-line string, with the name
on the left, storyFormat.
7-20 These lines contain the body of the string and the ending triple quotes. This storyFormat string
contains some special symbols making it a format string, unlike the string in lines 1-4. The

 
 
 
image
Anil  Bist

Skills    Python

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)