Last active
April 30, 2018 02:03
-
-
Save davidsaccavino/3908cc77fc0165a9185689a65f431683 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! python 3 | |
# db.py - database query program | |
Houses = {'San Francisco' : '$1,375,000', 'New York City' : '$1,600,000', 'Austin' : '$579,000'} | |
Cars = {'F-Type' : '80,000', 'Aventador' : '400,000', 'Civic' : '25,000'} | |
Laptops = {'Surface 4' : '1000', 'MacBook Pro' : '3000', 'ThinkPad' : '1300'} | |
subjects = [Houses, Cars, Laptops] | |
# It wasn't working because it was checking if 'Houses', | |
# a string, was in subjects instead of Houses, a variable. | |
# I was able to fix this (with help of NARCeric) by using eval on subjectInput. | |
def dbSearch(subject, item): | |
if subject in subjects: | |
print(subject[item]) | |
else: | |
print('That subject doesn\'t exist.') | |
print('enter a subject') | |
subjectInput = eval(input()) | |
print('enter an item') | |
itemInput = input() | |
dbSearch(subjectInput, itemInput) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment