0

I am trying to write a program for a class, that given a sold ticket, my matrix (15x30) should replace the available seat "#" by sold seat "*".

seats = []

for i in range (1,16):
    for i in range (1,31):
        seats.append("#")

while True:
    try:    
        x = int(input("SVP entrer le numéro de la rangée (1-15): "))
        for x in range (1,16):
            y = int(input("SVP entrer le numéro du siège (1-30): "))
            for y in range (1,31):
               b = ((x-1) * 30) + (y-1)
               s = "*"
               for b in len(seats):
                   seats[b] = seats[s]
        z = input("Voulez-vous acheter un autre sièges (o/n)? ")
        if z == "o":
            return True
       else: 
            return False 
    except ValueError:
        print("Désoler, ce siège à déjà été acheter.")
print(seats)
print("Fin du programme")

However, I have an error:

File "/Users/staceypoulet/Desktop/temp1.py", line 15, in <module>
    if z in len(seats):
for b in len(seats):
TypeError: 'int' object is not iterable

Could anyone help me see the mistake? Thank you in advance to anyone who gives me the time :)

Stacy P.
  • 11
  • 1
  • 1
    `I took out the most of my code` keeping from us which line might be `26`. (BTW., `seats[x*y]` looks _so wrong_.) What _are_ you trying to achieve with `z in len(seats)`? Looks like _bounds checking_ - `in` tests membership, it is not `0 <= <= `. – greybeard Dec 11 '16 at 23:04
  • @greybeard I changed my post and put the whole of my code there :) – Stacy P. Dec 12 '16 at 03:44
  • Thank you in advance for any help you might be able to bring ! @greybeard – Stacy P. Dec 12 '16 at 03:44
  • (For ideas how to handle a "matrix", start with [How to define two-dimensional array in python](http://stackoverflow.com/q/6667201/3789665).) – greybeard Dec 12 '16 at 09:11
  • (Check the indentation of "the `else`-statement.) – greybeard Dec 12 '16 at 09:12
  • I still have no idea what you are trying to do with "that `in`-statement", but `seats[x][y] = '*'` should be a start. – greybeard Dec 12 '16 at 09:14

1 Answers1

0

You want to check if z in seats. len(seats) is an integer number and does not have membership.

DYZ
  • 55,249
  • 10
  • 64
  • 93
  • I am sorry, I am new at this... What do you mean by does not ave membership? Or can I transform it into a str? – Stacy P. Dec 11 '16 at 22:50
  • Operator `in` checks if `z` is a part of collection `seats`. Function `len()` calculates the number of members in a collection. The result is just a number, not a collection. You cannot check if `z` is a part of a number. So, back to my answer: you want to check `if z in seats`, not `if z in len(seats)`. – DYZ Dec 11 '16 at 22:54
  • Great Thanks @DYZ! My def works now ! How ever what could I change if i want the modification i made (Sold ticket) to appear? Or more like change the matrix i have – Stacy P. Dec 11 '16 at 23:01