Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Linear search in python
# Linear search
import sys
from cs50 import get_string
def main():
# dictionary of menu items
lookup = ["pancakes", "eggs", "bacon", "coffee"]
menu = {
"pancakes" : "$8.00",
"eggs" : "$5.00",
"bacon" : "$3.00",
"coffee" : "$1.00"
# Prompt user
menuItem = get_string("Check price of which menu item? : ")
if menuItem in lookup:
print(f"Yes! We have fresh {menuItem}")
if menuItem in menu:
print(f"The price is {menu[menuItem]}")
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment