help

Mitya Sirenef msirenef at lightbird.net
Fri Jan 11 13:16:09 EST 2013


On 01/11/2013 09:24 AM, Matt Jones wrote:
> Pay isn't linked to the "people" in any way.  A dictionary would serve 
> this purpose better (at least in this simple example).
>
> database = {
>     'Mac' : 1000,
>     'Sam' : 2000
> }
>
> name = raw_input('Enter your name:')
> if name in database.keys(): print "your pay is $", database[name]


This can be simplified a bit as:

database = dict(Mac=1000, Sam=2000)
name = raw_input('Enter your name: ')
if name in database:
   print "your pay is $", database[name]



  -m



-- 
Lark's Tongue Guide to Python: http://lightbird.net/larks/




More information about the Python-list mailing list