First, there are some redundancies in your code that I suggest to delete. For instance, do not not assign unnecessary dummy variables. You assign year to x, and then 5 to x. Simply, assign 5 to year; the same goes for months.
Second, you get a wrong result because your formula is wrong. Your assignment asks you to find number of months in year(s) plus some additional months. Thus, your formula should be
answer= 12*years + months
Here is the code for the first part of the assignment, the second part is the reverse of the first. You should be able to figure that out. If not, ask.
years = 18
months = 27
answer = years*12 + months
print years,' years and ',months,' months are equivalent to:', answer,' months'