Skip to content

Instantly share code, notes, and snippets.

@sojohnnysaid
Created November 3, 2019 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sojohnnysaid/c97b8276518a87a22704d1d4147dfcbd to your computer and use it in GitHub Desktop.
Save sojohnnysaid/c97b8276518a87a22704d1d4147dfcbd to your computer and use it in GitHub Desktop.
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__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment