Rotating an object on z axis 180degrees C#.

I can’t seem to figure out why this code is sometimes working and other times not.
Sometimes when i press the key to rotate the object it works, and sometimes it doesn’t.
I just need an object to rotate 180 degrees on z axis. Any help would be appreciated.
code :

if (Input.GetKey(KeyCode.Keypad0)) {
 targetRotation = Quaternion.LookRotation(transform.forward, Vector3.right);
 transform.rotation = Quaternion.Slerp(targetRotation,transform.rotation, smooth * Time.deltaTime);
}

Here is a bit of code that will cause an object to rotate on its local ‘z’ axis on the push of a key:

#pragma strict

var targetRotation : Quaternion;
var smooth : float = 3.0;

function Start() {
	targetRotation = transform.rotation;
}

function Update() {
	if (Input.GetKeyDown(KeyCode.Keypad0)) {
		targetRotation = Quaternion.AngleAxis(180.0, transform.forward) * transform.rotation;
	}

	 transform.rotation = Quaternion.Slerp(transform.rotation,targetRotation, smooth * Time.deltaTime);
}