I was faced with a very strange problem. With print() this code works.
def max_pairwise_product(numbers): max_1 = max(numbers) numbers.remove(max_1) max_2 = max(numbers) return max_1 * max_2 if __name__ == '__main__': input_n = int(input()) print() # <- comment of this line breaks the code input_numbers = [int(x) for x in input().split()] print(max_pairwise_product(input_numbers))
If I comment or delete the 10-th line with print() I got an error:
Traceback (most recent call last): File "C:Users...maximum_pairwise_product_fast.py", line 12, in <module> print(max_pairwise_product(input_numbers)) File "C:Users...maximum_pairwise_product_fast.py", line 2, in max_pairwise_product max_1 = max(numbers) ValueError: max() arg is an empty sequence*
Process finished with exit code 1
I use Python 3.9. PyCharm. I tried to launch with different virtual environments with Python 3.8 and 3.10 – the same error. When I launch in Jupyter and Colab – it is fane – no error.
There are no issues with any other Python script. I used the installation for several months and there was nothing strange.
It is so strange that I have no idea. Could you please help me?
Advertisement
Answer
Thank you all for helping to refer me in the right direction. The reason for the error was a bug in PyCharm. It sent not was typed. The issue disappeared after the PyCharm update from version 2022.1.1 to 2022.1.2.