Skip to content

Tag: conditional-statements

How to only count valid inputs

I have a function that is supposed to take input, calculate the average and total as well as record count. The bug in the code is that: Even though I have added a try and except to catch errors, these errors are also being added to the count. How do I only count the integer inputs without making the “In…

For loops and conditionals in Python

I am new to Python and I was wondering if there was a way I could shorten/optimise the below loops: I tried this oneliner, but it doesn’t seem to work: Answer You can use itertools.product to handle the nested loops for you, and I think (although I’m not sure because I can’t see your data) y…