arrays - Python 3.4 TypeError: argument of type 'int' is not iterable -


i have array each position in array represents parking spot. value of each position in array (or parking lot) represents in parking spot (car, motorcycle, etc.). showspots function should show of spots vehicle in. example, showspots(car) (where car = 1) should show of spots (or positions in array) hold value 1.

however, when run code, 'typeerror: argument of type 'int' not iterable' on line 'if holder in parkinglot[x]:'

why getting error, , how fix it?

my code:

from random import *  parkinglot = [0, 1, 0, 2, 0, 0, 1]  empty = 0 car = 1 motorcycle = 2  def showspots(holder):     x in range(0, 6):         if holder in parkinglot[x]:             print(x)  def main():     print("there cars in lots:")     showspots(car)     print("there motorcycles in lots:")     showspots(motorcycle)  main() 

i think want if holder == parkinglot[x]:. doing in, python trying iterate through parkinglot[x] , check if holder in it. obviously, since can't list(1), error raised.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -