
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
![Olive Oyl gives Popeye a huge box containing a gift. Popeye, thinking that it was a large tin of spinach, opened
it quickly, but inside was a tin of mushroom soup and another box. When he opened the new box, it had a tin
of creamed corn and yet another new box. Eventually Popeye opened box after box until he did get a box with
the tin of spinach that he was thrilled to have, and thankfully he could finally stop opening boxes!
Given a list of tin labels representing the tins found in each of the boxes, from the largest box to the smallest
box, write the recursive function called countBoxes to count and return the number of boxes that Popeye
opens before he gets to his beloved tin of spinach. Use a main function to test your recursive function by:
• creating a list containing various tin item labels, or using the following list:
tinLabels = ["mushroom soup", "creamed corn",
"apple pie filling", "kidney beans", \
"chili", "custard", "peas and carrots", \
"spaghetti sauce", "sprouts", \
"green beans", "spinach", \
"tuna", " tomato paste "]
calling the recursive function that counts and returns the number of boxes that Popeye opens before he
finds the tin of spinach (you may assume that "spinach" exists in the list)
• displaying the result returned by the recursive function, countBoxes
Call the file containing your program popeye.py. No marks will be given for a non-recursive solution.
Sample output:
Number of boxes that Popeye opens before getting spinach: 11](https://content.bartleby.com/qna-images/question/57a5127d-07a2-48e2-986e-67b601a3f8bd/61069a13-fe8c-4c68-a1cd-263e328c387a/um6fz77_thumbnail.png)
Transcribed Image Text:Olive Oyl gives Popeye a huge box containing a gift. Popeye, thinking that it was a large tin of spinach, opened
it quickly, but inside was a tin of mushroom soup and another box. When he opened the new box, it had a tin
of creamed corn and yet another new box. Eventually Popeye opened box after box until he did get a box with
the tin of spinach that he was thrilled to have, and thankfully he could finally stop opening boxes!
Given a list of tin labels representing the tins found in each of the boxes, from the largest box to the smallest
box, write the recursive function called countBoxes to count and return the number of boxes that Popeye
opens before he gets to his beloved tin of spinach. Use a main function to test your recursive function by:
• creating a list containing various tin item labels, or using the following list:
tinLabels = ["mushroom soup", "creamed corn",
"apple pie filling", "kidney beans", \
"chili", "custard", "peas and carrots", \
"spaghetti sauce", "sprouts", \
"green beans", "spinach", \
"tuna", " tomato paste "]
calling the recursive function that counts and returns the number of boxes that Popeye opens before he
finds the tin of spinach (you may assume that "spinach" exists in the list)
• displaying the result returned by the recursive function, countBoxes
Call the file containing your program popeye.py. No marks will be given for a non-recursive solution.
Sample output:
Number of boxes that Popeye opens before getting spinach: 11
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps with 2 images

Knowledge Booster
Similar questions
- Suppose you always eat a particular brand of cookies out of the standard-sized package it comes in from the store, which has 4 rows of cookies in equal amounts. You notice that when you eat 3 at a time, there's always one cookie left over. you decide when you purchase the next package, you'll eat 5 at a time but still, there's always one cookie left over. Since it really isn't helpful to always have a leftover cookie you decide to eat 7 at a time and there are no cookies leftover, but you do notice that in your last grab of 7 cookies, you're one cookie shortarrow_forwardPython help Make the game Hanoi Tower. Ask first how many disks there are. After then, ask from the user the rods that will be used to remove and insert the disk. The program should verify the game's rules and see if the user has finished the task. After, Create an algorithm to solve the Tower of Hanoi, then test it with no more than six disks.arrow_forwardA bandit armed with a revolver approached a quaker as he strolled down a rural road. A robbery was in progress, and he said, "Your money or your life!" My buddy answered, "I can't give you my money because then I'd be helping you do evil, but exchange is legal, so here, take my pocketbook in return for your gun." The robber accepted the purse, but the Quaker put the pistol to his head and said, "Now friend, give me back my pocketbook or the weapon may go off fire," as recounted by the thief.arrow_forward
- A palindrome is a word spelled the same way backwards and forwards. For example, Anna, radar, madam and racecar are all palindromes. Certain words can be turned into palindromes when the first letter is removed and added at the back, e.g. 'potato' will read the same backwards if we remove the 'p' and add it at the back, i.e. 'otatop' read backwards will still say 'potato'. Similarly, 'banana' when you remove the 'b' and add it at the back so that it becomes 'ananab' will still say 'banana' if you read it backwards. Write a program that reads a word into a C-string (a character array). The program should then determine whether the word would be a palindrome if we remove the first character and add it at the back of the word. Use only C-string functions and C-strings. Assume that we will not work with words longer than 20 characters. Hint: You may consider using the C-string function strrev () but it is not compulsory. Remember to plan your program!arrow_forwardA quaker was walking down a country road when he was suddenly confronted by a robber brandishing a pistol. The robber exclaimed, "Your money or your life!" My friend replied, "I cannot deliver my money because I should be aiding thee in evildoing, but exchange is lawful, and I will give thee my purse for the pistol." The thief consented to accept the purse, then the quaker pointed the gun to the robber's head and said, "Now buddy, give me back my pocketbook or the weapon may go off fire," according to the robber.arrow_forwardA band of thieves comes up with a series of rules for hiding their loot so that they are always able to find it. The rules are as follows: If the house is next to a lake, then the treasure does not go in the kitchen If the tree in the front yard is an elm, then the treasure is in the kitchen The tree in the front yard is an elm or the treasure is buried under the flagpole If the tree in the backyard is an oak then the treasure is in the garage. You observe that the house where the treasure is hidden is next to a lake. Where is the treasure? discrete matharrow_forward
- Blue-Eyed Island: A bunch of people are living on an island, when a visitor comes with a strangeorder: all blue-eyed people must leave the island as soon as possible. There will be a flight out at8:00pm every evening. Each person can see everyone else's eye color, but they do not know theirown (nor is anyone allowed to tell them). Additionally, they do not know how many people haveblue eyes, although they do know that at least one person does. How many days will it take theblue-eyed people to leave?arrow_forwardputty program for unix can can not get the screen to show the mountain list. how do i do this?arrow_forwardA pistol-wielding robber approached a Quaker on a rural road. "Your money or your life!" shouted the thief. "Exchange is allowed, and I will offer thee my purse for the weapon," my buddy said. The thief accepted the handbag, then the quaker held the pistol to his head and said, "Now friend, give me back my pocketbook or the weapon may go off fire," according to the robber.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY