Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: help (http://www.velocityreviews.com/forums/t956431-re-help.html)

Mitya Sirenef 01-11-2013 06:16 PM

Re: help
 
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/



All times are GMT. The time now is 08:59 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.