Program 4 - Calorie Look-up

ANNOUNCEMENTS:
Some of the TAs suggested using the find method, rather than the in operator. It is probably easier to use the in operator to check for a substring in a string, but you may use either in this assignment. We will discuss find in lecture on Monday.

In this program, you'll begin with a file that defines a big, multi-line string, containing calorie counts for various items at Carl's Junior. The big string is already in this file: menu.py.

Your program should ask the user for a menu item, and then report how many calories it contains. If more than one item contains the search term the user enters, you can print them all.

The data also contains a category for each item. The user should be able to find items by category as well as by name, but the output of your program should not display the categories.

Example output

Here is an example of what running your program should look like. Blue is what Python types and black is what the user responds.

This program lets you enter a search term,
which should be a menu item from the Carls Junior
menu. Search terms should be capitalized.
Enter a menu item:
Santa Fe
Charbroiled Santa Fe Chicken Sandwich 510 calories

Here is another example.

This program lets you enter a search term,
which should be a menu item from the Carls Junior
menu. Search terms should be capitalized.
Enter a menu item:
Hamburger
Double Western Bacon Cheeseburger 900 calories
Famous Big Star(TM) Hamburger 580 calories
Jr. Hamburger 330 calories
Super Star Hamburger 790 calories
Western Bacon Cheeseburger 650 calories

And finally, here is an example where the search term is not in the menu.

This program lets you enter a search term,
which should be a menu item from the Carls Junior
menu. Search terms should be capitalized.
Enter a menu item:
pizza
There is no pizza on the menu.

Required Python techniques

You may not use while loops in this program, only for loops. I think the easiest first step will be to use the split method, splitting on the newline character \n, to break the long input string up into a list of lines, each of which is a menu item.

Saving and handing in the program

Please name your program yourUID+"4.py", where yourUID is your myUCDavis user ID. For instance, I login to myUCDavis as "amenta", so my program is named "amenta2.py".

Like last time, hand in your assignment using myUCDavis. Select ECS 10 from your list of courses on the right. Left-click "Assignments" near the upper left, and then "Project 4". Click on "Drop-Off" and then "Browse". Get to your Desktop, and then to the "ECS 10" folder you made, and finally select your file. The file name should appear in the box next to the "Browse" button. Click "drop-off" to hand in your program.

If you are working in the computer classrooms, remember to take your ECS 10 folder, and your program, with you on your flash-drive.