You are on page 1of 25

Starting Out with Programming Logic and Design

Lab 5: Repetition Structures


This lab accompanies Chapter 5 of Starting Out with Programming Logic & Design. Name !dam

Lab 5.1 Repetition Structures Pseudocode: Condition Controlled Loops


Critical "e#iew ! repetition structure causes a statement or set of statements to e$ecute repeatedl%. "epetition structures are used to perform the same tas& o#er and o#er. "epetition structures are commonl% called loops ! condition'controlled loop uses a true(false condition to control the number of times that it repeats. The general structure of a )hile loop with a condition'controlled statement is //Declare loop control variable While condition Statement Statement Etc. //Ask Question that changes the loop control variable End While The general structure of a Do )hile loop with a condition'controlled statement is //Declare loop control variable Do Statement Statement Etc. //Ask Question that changes the loop control variable While Condition *elp +ideo Double clic& the file to #iew #ideo

This lab re,uires %ou to implement a condition controlled loop.

Starting Out with Programming Logic and Design Step 1: .$amine the following main /odule from Lab 0.-. Loops are commonl% used to call modules multiple times. The best design is to use a loop around the module calls in /ain.
Module main ( //Declare local variables Declare !eal monthl"Sales Declare !eal storeAmount Declare !eal empAmount Declare !eal sales#ncrease //$unction calls Call getSales(monthl"Sales Call get#ncrease(sales#ncrease Call store%onus(monthl"Sales& storeAmount Call emp%onus(sales#ncrease& empAmount Call print%onus(storeAmount& empAmount End Module

Step 2: 1n the space pro#ided2 create a loop control #ariable named &eep3oing of the data t%pe string. 1nitiali4e this #ariable to 5%6. 7"eference /odulari4ing the Code in the 8od% of a Loop2 page 19-:. Step 3: 1n the space pro#ided2 write a while statement.
Module main ( //Declare local variables Declare !eal monthl"Sales Declare !eal storeAmount Declare !eal empAmount Declare !eal sales#ncrease Declare String keep'oing ( )"* //$unction calls While keep'oing (( )"* Call getSales(monthl"Sales Call get#ncrease(sales#ncrease Call store%onus(monthl"Sales& storeAmount Call emp%onus(sales#ncrease& empAmount Call print%onus(storeAmount& empAmount Displa" +Do "ou ,ant to run the program again(Enter " .or "es ./ #nput keep'oing End While End Module

Step 4: 1n the space pro#ided2 create a loop control #ariable named &eep3oing of the data t%pe string. 1nitiali4e this #ariable to 5%6. 7"eference )riting a Do')hile Loop2 page 195:.

Starting Out with Programming Logic and Design

Step 5: 1n the space pro#ided2 write a do while statement.


Module main ( //Declare local variables Declare !eal monthl"Sales Declare !eal storeAmount Declare !eal empAmount Declare !eal sales#ncrease Declare String keep'oing ( )"* //$unction calls Do Call getSales(monthl"Sales Call get#ncrease(sales#ncrease Call store%onus(monthl"Sales& storeAmount Call emp%onus(sales#ncrease& empAmount Call print%onus(storeAmount& empAmount Displa" +Do "ou ,ant to run the program again(Enter " .or "es ./ #nput keep'oing While keep'oing (( )"* End Module

Starting Out with Programming Logic and Design

Lab 5.2 Repetition Structures Pseudocode: Counter Controlled Loops


Critical "e#iew ! count'controlled loop repeats a specific number of times. The loop &eeps a count of the number of times that it iterates2 and when the count reaches a specified amount the loop stops. ! #ariable2 &nown as a counter #ariable2 is used to store the number of iterations that it has performed. The three actions that ta&e place are initiali4ation2 test2 and increment. 1nitiali4ation 8efore the loop begins2 the counter #ariable is initiali4ed to a starting #alue. Test The loop tests the counter #ariable b% comparing it to a ma$imum #alue. 1ncrement To increment a #ariable means to increase its #alue. This is done b% adding one to the loop control #ariable. !n% loop can be used with a count'controlled loop. ! running total is a sum of numbers that accumulates with each iteration of a loop. The #ariable used to &eep the running total is called an accumulator. *elp +ideo Double clic& the file to #iew #ideo

This lab re,uires %ou to write a complete program using a condition controlled loop2 a counter controlled loop2 and an accumulator. The program is a follows
Write a program that ,ill allo, a grocer" store to keep track o. the total number o. bottles collected .or seven da"s. 0he program should allo, the user to enter the total number o. bottles returned .or seven da"s. 0he program ,ill calculate the total number o. bottles returned .or the ,eek and the amount paid out (the total returned times .12 cents . 0he output o. the program should include the total number o. bottles returned and the total paid out.

Step 1: 1n the pseudocode below2 declare the following #ariables under the documentation for Step 1. ! #ariable called total8ottles that is initiali4ed to < o This #ariable will store the accumulated bottle #alues ! #ariable called counter and that is initiali4ed to 1 o This #ariable will control the loop ! #ariable called toda%8ottles that is initiali4ed to < o This #ariable will store the number of bottles returned on a da% ! #ariable called totalPa%out that is initiali4ed to <

Starting Out with Programming Logic and Design o This #ariable will store the calculated #alue of total8ottles times .1< ! #ariable called &eep3oing that is initiali4ed to 5%6 o This #ariable will be used to run the program again

Step 2: 1n the pseudocode below2 ma&e calls to the following functions under the documentation for Step -. ! function call to get8ottles that passes total8ottles2 toda%8ottles2 and counter. ! function called calcPa%out that passes totalPa%out and total8ottles. ! function called print1nfo that passes total8ottles and totalPa%out Step 3: 1n the pseudocode below2 write a condition controlled while loop around %our function calls using the &eep3oing #ariable under the documentation for Step ;. Complete Steps 1-3 below:
Module main ( //Step 1: Declare variables below Declare #nteger total%ottles ( 2 Declare #nteger counter ( 1 Declare #nteger toda"%ottles ( 2 Declare #nteger total3a"put ( 2 Declare Srting keep'oing ( )"* //Step 3: Loop to run program again While keep'oing (( )"* //Step 2: Call functions get%ottles(total%ottles& toda"%ottles& counter calc3a"out(total%ottles& toda"%ottles print#n.o(total%ottles& toda"%ottles Displa" +Do "ou ,ant to run the program again(Enter " .or "es ./ #nput keep'oing End While End Module

Step 4: 1n the pseudocode below2 write the missing lines2 including a. The missing parameter list b. The missing condition 7*int should run se#en iterations: c. The missing input #ariable d. The missing accumulator e. The increment statement for the counter
//get%ottles module Module get%ottles(a. Integer totalBottles to!a"Bottles Integer counter# While b. counter $%& Iteger

Starting Out with Programming Logic and Design

Displa" +Enter number o. bottles returned .or the da"46 #nput c. to!a"Bottles !. total%ottles ( total%ottles 5 toda"%ottles e. counter % counter ' 1 End While End Module

Step 5: 1n the pseudocode below2 write the missing lines2 including a. The missing parameter list b. The missing calculation
//get%ottles module Module calc3a"out(a.(eal total)a"out Integer totalBottles# total3a"out ( 2 //resets to 2 .or multiple runs b. total)a"put % totalBottles * .1+ End Module

Step : 1n the pseudocode below2 write the missing lines2 including a. The missing parameter list b. The missing displa% statement c. The missing displa% statement
//print#n.o module Module print#n.o(a. (eal total)a"out Integer totalBottles# b. Displa" ,-.e total number of bottles return was/ totalBottles c. Displa" ,-.e total pa"out for t.e bottles was 0/ total)a"out End Module

Starting Out with Programming Logic and Design

Lab 5.3 !lowc"arts


Critical "e#iew 1n a while loop2 the ,uestion is as&ed first. !fter the statements process2 the control goes bac& abo#e the condition.

1n a do'while loop2 the ,uestion is as&ed last. The statements alwa%s process at least one time.

1n "aptor2 %ou can place the modules before or after the condition depending on whether %ou want to use a do'while or a while loop.
*elp +ideo Double clic& the file to #iew #ideo

This lab re,uires %ou to con#ert %our pseudocode in Lab 5.- to a flowchart. >se an application such as "aptor or +isio.

Starting Out with Programming Logic and Design

Step 1: Start "aptor and sa#e %our document as Lab 5-3. The .rap file e$tension will be added automaticall%. Start b% adding a Comment bo$ that declares %our #ariables. The onl% #ariable from Lab 5.- that is different is the &eep3oing #ariable. Name this endProgram instead. Step 2: Clic& the Loop s%mbol and drag and drop it between the Start and the .nd s%mbol. Step 3: Clic& the 1nput s%mbol and drag and drop it between the Loop s%mbol and the Diamond s%mbol. Step 4: Double clic& the 1nput s%mbol and as& the ,uestion 5Do %ou want to end the program@ .nter %es or no 6. Store the answer in the endProgram #ariable. Step 5: Double clic& the Diamond s%mbol2 and t%pe endProgram A B%esB as the condition. )hen the program e$ecutes2 the user must t%pe B%esB e$actl%2 in order for the program to end. Now2 main should loo& as the following

Step : The ne$t step in %our flowchart should be to call %our methods. !dd %our modules under the Loop o#al. 8e sure to clic& %es to add new tabs for each module. Now2 main should loo& as the following

Starting Out with Programming Logic and Design

Step #: Clic& on the get8ottles tab. !dd a Loop s%mbol between the Start and .nd s%mbols. Double clic& the Diamond s%mbol and enter the condition as counter D9. Step $: !dd an 1nput s%mbol and add the code 5.nter the number of bottles returned for toda% 6. Store the #alue in the toda%8ottles #ariable. Step %: !dd an !ssignment s%mbol ne$t and set total8ottles to total8ottles E toda%8ottles. Step 1&: !dd another !ssignment s%mbol ne$t and set counter to counter E 1. Step 11: Sa#e %our program and tr% running it. FouGll notice an error occur when the loop starts processing in the get8ottles module. This is because total8ottles does not ha#e a starting #alue.

Starting Out with Programming Logic and Design

1<

Step 12: To fi$ the error2 to set the counter to 12 and to reset the toda%8ottles bac& to < for multiple repetitions2 add three !ssignment s%mbols abo#e the Loop s%mbol. 1n one s%mbol2 set counter to 1. 1n the other2 set total8ottles to <. 1n the other2 set toda%8ottles to <. Four get8ottles module should loo& as follows

Starting Out with Programming Logic and Design

11

Step 13: Clic& the calcPa%out module and add an !ssignment s%mbol. Set totalPa%out to total8ottles times .1<. Step 14: Clic& the print1nfo module and add two Output s%mbols that print the total bottles returned and the total amount paid out. Step 15: Test %our program against the following #alues. 1f there is an error2 go bac& through the steps to locate the problem. 'nput (alues Se#en da%s of bottles ;0= -;? =;? ?C< 1<;5 ?CC 5;= )*pected +utput The total number of bottles collected were 05?The total amount paid out is H05?.-<<<

Step 1 : The final step is to insert %our finished flowchart in the space below. PASTE FLOWCHART HERE

Starting Out with Programming Logic and Design

1-

Starting Out with Programming Logic and Design

1;

Lab 5.4 P,t"on Code


Critical "e#iew 1n P%thon2 %ou use the while statement to write a condition'controlled loop. The loop has two parts 71: a condition that is tested for a true or false #alue2 and 7-: a statement or set of

statements that is repeated as long as the condition is true. ! while loop can also be used for count'controlled loops. *ere is the general format of the ,hile loop in P%thon ,hile condition4 statement statement etc. Since the while loop is a pre'test2 it is important to initiali4e %our loop control #ariable to a starting #alue so that the first iteration will be true. !s with all loops2 be sure to change the loop control #ariable either b% incrementing or as&ing a ,uestion.
*elp +ideo Double clic& the file to #iew #ideo

The goal of this lab is to con#ert the 8ottle "eturn program to P%thon code. Step 1: Start the 1DL. .n#ironment for P%thon. Prior to entering code2 sa#e %our file b% clic&ing on Iile and then Sa#e. Select %our location and sa#e this file as Lab5-4.py. 8e sure to include the .p% e$tension. Step 2: Document the first few lines of %our program to include %our name2 the date2 and a brief description of what the program does. Step 3: Start %our program with the following code for main
67ab 89: 0he %ottle !eturn 3rogram 6the main .unction de. main( 4 6calls main main(

Starting Out with Programming Logic and Design

10

Step 4: P%thon onl% supports )hile loops2 so endProgram must be initiali4ed to JnoG. >nder de. main( 4& create a #ariable called endProgram and set it to JnoG such as
end3rogram ( ;no;

Step 5: The ne$t step is to write a while statement with the condition of endProgram AA JnoG . The statement should be aligned with the statement in Step 0. The code should be as follows
,hile end3rogram (( ;no;4

Step : The code inside of the while statement should be tabbed o#er and include %our function calls. The function get8ottles7: will return total8ottles so the call should be set to that #ariable. The function calcPa%out should pass total8ottles as an argument and will return totalPa%out from the function. The function print1nfo should pass total8ottles and totalPa%out as arguments. The code should loo& as follows
total%ottles ( get%ottles( total3a"out ( calc3a"out(total%ottles print#n.o(total%ottles& total3a"out

Step #: The ne$t step is to modif% the loop control #ariable. This is done with a simple rawKinput statement such as
end3rogram ( ra,<input(;Do "ou ,ant to end the program(Enter "es or no 4 ;

Step $: The ne$t function to code is get8ottles. )rite a definition for get8ottles that accepts no arguments. The code should loo& as follows
6this .unction ,ill get the number o. bottles returned de. get%ottles( 4

Step %: The first step in %our function should be to set %our #ariables to #alues. 1n P%thon and most programming languages2 in order for #ariables to be used2 the% need to ha#e a starting #alue. This also allows for a reset of the #ariables when the program runs again. Set total8ottles and toda%8ottles to < and counter to 1. Four code should loo& as follows
total%ottles ( 2 toda"%ottles ( 2 counter ( 1

Step 1&: )rite a while loop with the condition of counter LA 9. This code should loo& as follows
,hile counter =( >4

Starting Out with Programming Logic and Design

15

Step 11: 1nside the while loop2 write a statement that allows the user to enter the number of bottles for toda%. This code should loo& as follows
toda"%ottles ( input(;Enter number o. bottles .or toda"4 ;

Step 12: Ne$t2 write the accumulator statement. This code should loo& as follows
total%ottles ( total%ottles 5 toda"%ottles

Step 13: The last statement inside the loop should increment counter b% one so the loop will end after se#en iterations. This code should loo& as follows
counter ( counter 5 1

Step 14: The final statement in the get8ottles function is to return total8ottles bac& to main. This code should loo& as follows
return total%ottles

Step 15: Create a function definition for calcPa%ment that accepts total8ottles in the parameter list. This function should first reset totalPa%out to <. This is done so that on multiple iterations of the program2 totalPa%out is reset to <. The second step in this function is to calculate totalPa%out as total8ottles times .1<. The last step is to return totalPa%out. Four code should loo& as follows
6this .unction ,ill calculate the pa"out de. calc3a"out(total%ottles 4 total3a"out ( 2 total3a"out ( total%ottles ? .12 return total3a"out

Step 1 : The final function in this program is print1nfo. This function accepts two #ariables in the parameter list so that it can displa% the total number of bottles returned and the total amount paid out. Four code should loo& as follows
6this .unction ,ill displa" the in.ormation de. print#n.o(total%ottles& total3a"out 4 print ;0he total number o. bottles collected is;& total%ottles print ;0he total paid out is @;& total3a"out

Step 1#: Clic& "un and "un /odule to see how %our program processes. Test the following #alues to #erif% the e$pected output. AAA Enter number o. bottles .or toda"4 B:C

Starting Out with Programming Logic and Design Enter number o. bottles .or toda"4 DBE Enter number o. bottles .or toda"4 CBE Enter number o. bottles .or toda"4 EF2 Enter number o. bottles .or toda"4 12B8 Enter number o. bottles .or toda"4 EFF Enter number o. bottles .or toda"4 8BC 0he total number o. bottles collected is :8ED 0he total paid out is @ :8E.D Do "ou ,ant to end the program- (Enter "es or no 4 no Enter number o. bottles .or toda"4 :D8 Enter number o. bottles .or toda"4 B:D Enter number o. bottles .or toda"4 DB8 Enter number o. bottles .or toda"4 8BF Enter number o. bottles .or toda"4 :E8 Enter number o. bottles .or toda"4 BD1 Enter number o. bottles .or toda"4 1DE 0he total number o. bottles collected is D:>8 0he total paid out is @ D:>.8

1=

Do "ou ,ant to end the program- (Enter "es or no 4 "es AAA Step 1$: .$ecute %our program so that it wor&s and paste the final code below #Lab 5-4 The Bottle Return Program #the main function def main(): endProgram = 'no' hile endProgram == 'no': !rint #!rint" a blan# line totalBottle" = getBottle"() totalPa$out = calcPa$out(totalBottle") !rint%nfo(totalBottle"& totalPa$out) !rint endProgram = ra 'in!ut ('(o $ou (*nter $e" or no): ') ant to end the !rogram)

#thi" function ill get the number of bottle" retruned def getBottle"(): totalBottle" = +

Starting Out with Programming Logic and Design toda$Bottle" = + counter = , hile counter -= .: toda$Bottle" = in!ut('*nter number of bottle" for toda$: ') totalBottle" = totalBottle" / toda$Bottle" counter = counter / , return totalBottle" #thi" function ill calcualte the !a$out def calcPa$out(totalBottle"): totalPa$out = + totalPa$out = totalBottle" 0 1,+ return totalPa$out #thi" function ill di"!la$ the information def !rint%nfo(totalBottle"& totalPa$out): !rint 'The total number of bottle" collected i"' & totalBottle" !rint 'The total !aid out i" 2' & totalPa$out #call" main main()

19

Starting Out with Programming Logic and Design

1?

Lab 5.5 Pro-rammin- C"allen-e 1 .um .um /ur-er 0oint


)rite the Ilowchart and P%thon code for the following programming problem and the pseudocode below.

)rite a program that will calculate the cost of purchasing a meal. This program will include decisions and loops. Details of the program are as follows Four menu items onl% include the following food with accompanied price o Fum Fum 8urger A .CC o 3rease Fum Iries A .9C o Soda Fum A 1.<C !llow the user of the program to purchase an% ,uantit% of these items on one order. !llow the user of the program to purchase one or more t%pes of these items on one order. !fter the order is placed2 calculate total and add a =M sales ta$. Print to the screen a receipt showing the total purchase price.

Four sample output might loo& as follows


Enter 1 .or Gum Gum %urger Enter D .or 'rease Gum $ries Enter B .or Soda Gum Enter no, 9A1 Enter the number o. burgers "ou ,ant B Do "ou ,ant to end "our order- (Enter "es or no 4 no Enter 1 .or Gum Gum %urger Enter D .or 'rease Gum $ries Enter B .or Soda Gum Enter no, 9AB Enter the number o. sodas "ou ,ant D Do "ou ,ant to end "our order- (Enter "es or no 4 no Enter 1 .or Gum Gum %urger Enter D .or 'rease Gum $ries Enter B .or Soda Gum Enter no, 9A1 Enter the number o. burgers "ou ,ant 1 Do "ou ,ant to end "our order- (Enter "es or no 4 no Enter Enter Enter Enter 1 .or Gum Gum %urger D .or 'rease Gum $ries B .or Soda Gum no, 9AD

Starting Out with Programming Logic and Design


Enter the number o. .ries "ou ,ant D Do "ou ,ant to end "our order- (Enter "es or no 4 "es 0he total price is @ E.1EBD Do "ou ,ant to end program- (Enter no to process a ne, order 4 no Enter 1 .or Gum Gum %urger Enter D .or 'rease Gum $ries Enter B .or Soda Gum Enter no, 9AD Enter the number o. .ries "ou ,ant D Do "ou ,ant to end "our order- (Enter "es or no 4 no Enter 1 .or Gum Gum %urger Enter D .or 'rease Gum $ries Enter B .or Soda Gum Enter no, 9AB Enter the number o. sodas "ou ,ant D Do "ou ,ant to end "our order- (Enter "es or no 4 "es 0he total price is @ B.FE8C Do "ou ,ant to end program- (Enter no to process a ne, order 4 "es

1C

1"e Pseudocode /odule main7: Call declare+ariables7endProgram2 endOrder2 total8urger2 totalIr%2 totalSoda2 total2 ta$2 subtotal2 option2 burgerCount2 fr%Count2 sodaCount: ((Loop to run program again )hile endProgram AA 5no6 Call reset+ariables7total8urger2 totalIr%2 totalSoda2 total2 ta$2 subtotal: ((Loop to ta&e in order )hile endOrder AA 5no6 Displa% 5.nter 1 for Fum Fum 8urger6 Displa% 5.nter - for 3rease Fum Iries6 Displa% 5.nter ; for Soda Fum6 1nput option 1f option AA 1 Then Call get8urger7total8urger2 burgerCount: .lse 1f option AA - Then Call getIr%7totalIr%2 fr%Count: .lse 1f option AA ; Then Call getSoda7totalSoda2 sodaCount:

Starting Out with Programming Logic and Design .nd 1f Displa% 5Do %ou want to end %our order@ 7.nter no to add more items :6 1nput endOrder .nd )hile Call calcTotal7burgerTotal2 fr%Total2 sodaTotal2 total2 subtotal2 ta$: Call print"eceipt7total: Displa% 5Do %ou want to end the program@ 7.nter no to process a new order:6 1nput endProgram .nd )hile .nd /odule

-<

/odule declare+ariables7String "ef endProgram2 String "ef endOrder2 "eal "ef total8urger2 "eal "ef totalIr%2 "eal "ef totalSoda2 "eal "ef total2 "eal "ef ta$2 "eal "ef subtotal2 "eal "ef option2 "eal "ef burgerCount2 "eal "ef fr%Count2 "eal "ef sodaCount: Declare String endProgram A 5no6 Declare String endOrder A 5no6 Declare "eal total8urger A < Declare "eal totalIr% A < Declare "eal totalSoda A < Declare "eal total A < Declare "eal ta$ A < Declare "eal subtotal A < Declare 1nteger option A < Declare 1nteger burgerCount A < Declare 1nteger fr%Count A < Declare 1nteger sodaCount A < .nd /odule /odule reset+ariables 7"eal "ef total8urger2 "eal "ef totalIr%2 "eal "ef totalSoda2 "eal "ef total2 "eal "ef ta$2 "eal "ef subtotal: ((reset #ariables total8urger A < totalIr% A < totalSoda A < total A < ta$ A < subtotal A < .nd /odule

Starting Out with Programming Logic and Design /odule get8urger7"eal "ef total8urger2 1nteger burgerCount: Displa% 5.nter the number of burgers %ou want6 1nput burgerCount Set total8urger A total8urger E burgerCount N .CC .nd /odule /odule getIr%7"eal "ef totalIr%2 1nteger fr%Count: Displa% 5.nter the number of fries %ou want6 1nput fr%Count Set totalIr% A totalIr% E fr%Count N .9C .nd /odule /odule getSoda7"eal "ef totalSoda2 1nteger sodaCount: Displa% 5.nter the number of sodas %ou want6 1nput sodaCount Set totalSoda A totalSoda E sodaCount N 1.<C .nd /odule /odule calcTotal7"eal total8urger2 "eal totalIr%2 "eal totalSoda2 "eal "ef total2 "eal subtotal2 "eal ta$: Set subtotal A total8urger E totalIr% E totalSoda Set ta$ A subtotal N .<= Set total A subtotal E ta$ .nd /odule /odule print"eceipt7"eal total: Displa% 5Four total is H62 total .nd /odule 1"e !lowc"art

-1

Starting Out with Programming Logic and Design

--

Starting Out with Programming Logic and Design

-;

1"e P,t"on Code Othe main function Def main7: .nd program A JnoG Print )hile endProgram AA JnoG total8urger A < totalIr% A < totalSoda A < endOrder A JnoG while endOrder AA JnoG print print J.nter 1 for Fum Fum 8urgerG print J.nter - for 3rease Fum IriesG print J.nter ; for Soda FumG option A input 7J.nter now 'DG: if option A 1 total8urger A get8urger7total8urger: elif option AA totalIr% A getIr% 7totalIr%: elif option AA ;

Starting Out with Programming Logic and Design totalSoda A getSoda7totalSoda: else print JFou ha#e entered an in#alid optionPPPG endOrder A rawKinput 7JDo %ou want to end %our order@ 7.nter %es or no: J: print total A calcTotal7total8urger2 totalIr%2 totalSoda: print"eceipt7total:

-0

endProgram A rawKinput 7JDo %ou want to end the program@ 7.nter no to process a new order: J: Othis function will get burger order Def get8urger 7total8urger: burgerCount A input 7J.nter the number of burgers %ou want J: total8urger A total8urger E burgerCount N .CC return total8urger Othis function will get fr% order Def getIr% 7totalIr%: fr%Count A input 7J.nter the number of fries %ou wantG: totalIr% A totalIr% E fr%Count N .9C return totalIr% Def getSoda sodaCount A input 7J.nter the number of soda %ou wantG: totalSoda A totalSoda E sodaCount N 1.<C def calcTotal 7total8urger2 totalIr%2 totalSoda: subtotal A total8urger E totalIr% E totalSoda ta$ A subtotal N .<= total A subtotal E ta$ return total def print"eceipt7total: print JThe total price is HG 2 total Ocalls main /ain7:

Starting Out with Programming Logic and Design

-5

You might also like