[Answered ]-Range(1,1) is not processed by loop

0👍

You could use a conditional:

range(1, product_stock if product_stock > 1 else 2)

this, in the case that product_stock is 1, yields a range(1, 2) which results in a single iteration (which is what you say you need).

1👍

You will need to change range(1, product_stock) to range(0, product_stock) or range(product_stock) for short (the default is zero), since indexing starts at 0 for most programming languages, including Python.

👤Taku

1👍

I think you have a bug for all product counts, its just more pronounced when count is 1. Suppose you have 4 products, range(1, 4) only counts 1, 2, 3. That’s because range is open… it doesn’t include the terminating number. You are always displaying one too few products, its just most pronounced when count is 1. The normal way to solve this is

 'product_stock_range'   : range(1, product_stock+1),

Leave a comment