Your code is concise, readable, and idiomatic. It works as you intended. It's small but nice snippet of code.
You could probably turn it into a one-liner, but it would get rather complex and readability would suffer, implying issues with maintainability, re-usability and reviewing.
Regarding style, I have two minor remarks:
- The indentation is unusual, PEP 8 and recommends 4 spaces for indents, not 8. But this might as well be an issue with question formatting.
- The variable names you chose,
x
and y
, are undescriptive. I would prefer weeks
and cost_per_week
, although your approach of using the names in the problem description is understandable.
I have a bigger issue with your use of input
for getting data. From what I understand from the input format description, I expect the format to be a text file. Expecting the user to copy, line by line, the input data fails to solve the problem in my book. Python makes it quite easy to work with files and iterating over lines. You should look into the open
built-in function and work with that.
In any case, when working with user input, you should validate that input and handle invalid input gracefully. Imagine mis-typing a line on the 99-th test case out of 100, your code would crash and the user would need to start over from the top. You can expect an input file to be properly formatted, but that assumption doesn't hold for data gotten through input
.
The use of print
for output is also sub-optimal, as you would like to validate test cases programmatically. However, in this case, since the test data doesn't provide expected values, it is a decent approach, for lack of a better solution.