# Dictionary Remember we talked about those allow quick lookups google python dictionary # for more information y_or_n_to_bool = {'y': True, 'n': False} # input to get name as a string name = raw_input("what is your name") # input to get Y, N turn input into lower too match dictionary key flagString = raw_input("Please enter Y/N").lower() # turn string into boolean so we can use later google python boolean if interested flag = y_or_n_to_bool[flagString] # print the name and the flag we set print(name, flag)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question