If the condition is so bad as to affect habitability--i.e. it's more than "just" noticeable--then the tenant should be able to deduct the cost of replacing the carpet if the landlord, after written notice of the condition and a reasonable chance to take action, fails to correct the situation (first the landlord must have a chance to fix things). If it's not so bad as to affect habitability, then the tenant would not be entitled to do this--conditions have to rise to the level of making the premises unfit for their intended purpose (i.e. residence) before a tenant may act in this way.This could easily lead to litigation, if the landlord does not or will not believe the condition was that bad. It would be better to try to work things out with the landlord that the tenant will pay part and the landlord pay part, if possible.