Without user input validation the code can be quite simple:
And of course - while dealing with floats one must remember:
quantity = int(input('How many items do you have: ')) total = sum(float(input(f"Enter the price of item #{i+1}: ")) for i in range(quantity))However, if user enters anything what can't be converted into int/float program will rise
ValueError
. Its upon parameters of task if one should be defensive against it.And of course - while dealing with floats one must remember:
>>> 0.1 + 0.1 + 0.1 == 0.3 False
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.