Skip to content

Instantly share code, notes, and snippets.

@davegotz
Created March 5, 2019 18:40
Show Gist options
  • Save davegotz/1e5917eb56e8dfc0d91594f1a6fd61d1 to your computer and use it in GitHub Desktop.
Save davegotz/1e5917eb56e8dfc0d91594f1a6fd61d1 to your computer and use it in GitHub Desktop.
Functions with "search in a book" example.
import random
def query(book):
query_string = input("What do you want to look for?")
if query_string in book:
print("Yes, it is in the book.")
else:
print("No, it is not in the book")
def main():
book = ["This", "is", "my", "greatest","book","ever"]
book2 = ["This", "is", "my", "worst","book","ever"]
query(book)
query(book2)
main()
@gleich
Copy link

gleich commented Mar 5, 2019

Just a little suggestion, adding \n to the end of the string in the input function makes it so that the user types one line below the question. Example:

query_string = input("What do you want to look for?\n")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment