Created
February 23, 2017 19:12
-
-
Save caffeine-potent/0eebfaa7ffbb823fb15bbff6715cd34a to your computer and use it in GitHub Desktop.
Extending Dict to Ask for user input.
This file contains hidden or 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
class info(dict): | |
def add_item(self, item_name, question, type = None): | |
answer = raw_input(question) | |
if type is not None: | |
answer = type(answer) | |
self[item_name] = answer | |
a = info() | |
a.add_item("name", "What is your name? ") | |
a.add_item("quest", "What is your quest? ") | |
a.add_item("wsv", "What is the air speed velocity of an uladen swallow? ") | |
print(a) | |
print(a["name"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment