u/Dense_Quarter_5374

Type Error: 'bool' object is not iterable - what is this error and how can I solve it?

I have some code with a function restock_warehouse, that adds to the current stock 5 times while the current stock is smaller than the target stock. My question is, how can I fix the function so that the code works properly with and the print() call is displayed in the terminal?

The error message I have been receiving is:

```

Traceback (most recent call last):

File "file_name", line 15, in <module>

final_stock = restock_warehouse(10, 25)

File "file_name", line 5, in restock_warehouse

for i in range(5) and current_stock < target_stock:

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

TypeError: 'bool' object is not iterable

```

I have already tried wrapping the conditional part of the loop in parentheses, but it hasn't worked and I don't exactly understand the error message.

Version information: I'm on Python 3.9.6

def restock_warehouse(current_stock, target_stock):
    print("Starting warehouse restock system...")


    # We want to keep adding items until we reach our target stock
    for i in range(5) and current_stock &lt; target_stock:
        print(f"Current inventory level: {current_stock}")


        current_stock == current_stock + 5


    print("Warehouse restock complete!")
    return current_stock



# Start with 10 items, target goal is 25 items
final_stock = restock_warehouse(10, 25)
print(f"Final stock total: {final_stock}")
reddit.com
u/Dense_Quarter_5374 — 1 day ago

Is it just my Matplotlib glitching or did they update something that PCC didn't explain?

I'm currently following PCC third edition, using a colormap on a random walk with 5000 points.

This is my code: for the thing, and I'm sure the import stuff works correctly. My output though, is a constant blue hue instead of a gradient. Everything else works perfectly. Any ideas why?

import matplotlib.pyplot as plt


from random_walk import RandomWalk


# Keep making new walks, as long as the program is active.


while True:
    # Make a random walk
    rw = RandomWalk()
    rw.fill_walk()


    # Plot the points in the walk.
    plt.style.use('classic')
    fig, ax = plt.subplots()
    point_numbers = range(rw.num_points)
    ax.scatter(rw.x_values, rw.y_values, c=point_numbers, cmap=plt.cm.Blues,
               edgecolors='none', s=15)
    ax.set_aspect('equal')
    plt.show()


    keep_running = input("Make another walk? (y/n): ")
    if keep_running == 'n':
        break
reddit.com
u/Dense_Quarter_5374 — 2 months ago