git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(New to Python) Shopping List Code


On 2019-10-28 06:42:46 -0700, ferzan saglam wrote:
> How can I stop this code when -1 is typed or at a maximum item count of ten.

I'm just rewriting that sentence in Python:

> At the moment the code seems to be in a infinite loop meaning it keeps on asking for an entry until -1 is typed 
> 
> 
> total = 0
> while True:
>
>   print('Cost of item')
>
>   item = input()
>
>   if item != -1:
>     total = total + item
>   if item == -1:

    if item == -1 or count > 10:

>
>       break
>
> print(total)

Now it is up to you increment the variable count for each item.

Does that help?

        hp

-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp at hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20191028/502dfc3b/attachment.sig>