Sie sind auf Seite 1von 2

CS 170 Section _03_ Lab 6 An Acronym Generator

Name_ _

Due: No later than the beginning of class, Wed. 10/3/12 Recall from the class the pro ram !e !rote to "eco"e a se#$ence of ASC%% n$mbers into the strin that the n$mbers represent& 'e !ant to !rite a similar pro ram that !ill prompt the $ser for a strin an" then print o$t the acronym for the strin & (An acronym is a !or" forme" form the first letters of each !or" of a phrase&) *or e+ample, if the $ser inp$ts the strin -b$siness. acco$ntin "epartment-, the o$tp$t of yo$r pro ram sho$l" be the strin -/A0-& 1he acronym sho$l" be printe" $sin capital letters& 2ere is the al orithm !e !ill $se3 Step 1) Step 5) Step 3) Step 7) Step 8) Step 6) Step 7) 1) 4rompt the $ser to enter a strin & %nitiali6e an acc$m$lator strin Split the strin into a list of strin s Loop once for each strin in the list 4aste the first letter of the c$rrent strin from the list onto the acc$m$lator strin Con9ert the strin to capital letters 4rint o$t the strin containin the acronym&

'rite a 4ython statement that !ill prompt the $ser to enter a strin an" store it in an appropriately name" 9ariable& Destr = input( Please enter your desired phrase/title to acronym-ate:) *Destr= Desired String *Acronymate: he act o! turning a phrase or title into an acronym" #y: $ercedes %en&ins"

5)

'rite a 4ython statement to initiali6e a strin 9ariable so that it contains no characters& accu =

3)

'rite a 4ython statement that !ill ta:e the strin inp$t by the $ser, split it into a list of strin s an" store it in another 9ariable& ;a:e s$re the 9ariable is name" appropriately& listrings = Destr"split( )

7)

'rite a 4ython loop that !ill iterate o9er each strin in the list yo$ create" in step 3& /e s$re to $se an appropriately name" 9ariable for the loop in"e+& !or phrastring in listrings():

8)

As yo$r 4ython loop iterates o9er each strin in the list, yo$ !ant to e+tract the first letter of the c$rrent strin from the list an" concatenate it to the acc$m$lator 9ariable& 'rite an assi nment

statement that e+tracts the first letter of the strin store" in the loop in"e+ an" stores it in a 9ariable& !irst = phrastring'() 6) 'rite an assi nment statement that ta:es the letter store" in this 9ariable an" concatenates it on the en" of the acc$m$lator strin & acro*in = acro*in+!irst 7) 'hich 4ython strin library f$nction con9erts the characters in a strin to $pper case< "upper() =) Assemble all the statements from steps 1 thro$ h 7 into a f$nction that fin"s an" prints appropriately labele" acronyms !ith the acronym in all $pper case letters& Call yo$r f$nction -acronym_maker"&

What to turn in: 'hen yo$ ha9e finishe" !ith yo$r f$nction, sa9e the mo"$le as -acronym_maker.py- an" r$n the f$nction se9eral times $ntil yo$ are certain that it !or:s correctly& 1hen, print o$t a copy of the mo"$le that contains the f$nction, staple it $n"erneath this lab sheet, !rite yo$r name at the top of the lab sheet an" t$rn it in& No printe" mo"$le o$tp$t is re#$ire"&

Das könnte Ihnen auch gefallen