newbie question!

B

Brian

Hi, im new to python and have a simple question...

i want too have a list of values - say numbers of tables in a restaurant...
1,2,3,4,5. i want to associate a value with each of these numbers... eg. yes
or no. when a person books table 2, the value corresponding to 2 turns to no
[not available] etc...

what would be the best way to do this ? a little code help would help aswell
!!! - newbie

thanks,

Brian
 
J

Jay Dorsey

Brian said:
Hi, im new to python and have a simple question...

i want too have a list of values - say numbers of tables in a restaurant...
1,2,3,4,5. i want to associate a value with each of these numbers... eg. yes
or no. when a person books table 2, the value corresponding to 2 turns to no
[not available] etc...

what would be the best way to do this ? a little code help would help aswell
!!! - newbie

You could use a dictionary to hold the information:
.... tables = "no"
....
>>> tables[2] = "yes"
>>> for table in tables:
.... print "%2d : %s" % (table, tables
)
....
1 : no
2 : no
3 : no
4 : no
5 : no
6 : no
7 : no
8 : no
9 : no
10 : no


Jay
 
P

Patrick Useldinger

Hi, im new to python and have a simple question...

i want too have a list of values - say numbers of tables in a restaurant...
1,2,3,4,5. i want to associate a value with each of these numbers... eg. yes
or no. when a person books table 2, the value corresponding to 2 turns to no
[not available] etc...

usa a dictionnary, and boolean values True/False:

# initialize
tables = { 1:True, 2:True, 3:True }

# customer reserves table 2
tables[2]=False

# tables is now {1: True, 2: False, 3: True}
 
J

Jay Dorsey

Jay said:

That should be:

2 : yes

I was testing the code in a different computer than I typed this message
on, so I wrote it all out by hand; oops :)

Jay
 
T

Terry Reedy

Brian said:
Hi, im new to python and have a simple question...

i want too have a list of values - say numbers of tables in a restaurant...
1,2,3,4,5. i want to associate a value with each of these numbers... eg. yes
or no. when a person books table 2, the value corresponding to 2 turns to no
[not available] etc...

what would be the best way to do this ? a little code help would help aswell
!!! - newbie

Give n tables beginning with table 1, one could use a list initialized
as
tables = (n+1)*[True]
Then 'tables[2] = False' when booked.
But I would start with 'tables = (n+1)*[False]' so I could write
tables[2] = <booking information>
when booked rather than merely True for booked.

You can either ignore tables[0] or use it to keep a count of free
tables, in which case initialize tables[0]=n and subtract 1 for each
booking.

Terry J. Reedy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,167
Messages
2,570,911
Members
47,453
Latest member
MadelinePh

Latest Threads

Top