How to make an object roate 180 on Z axis on each mouse click

I’m working on a project for school and I need an object to rotate 180 degrees when selected with the mouse. The first attempt only got the object to rotate a little each time however with some assistance I came up with the code below. The issue however is that while it rotates the first time 180, every other time it rotates 360. How do I correct my script so that it is operating properly (rotating 180 each time it is selected - basically flipping to upside down) Below is the code I currently have that is giving me the issue.

Many thanks,

Chris

using UnityEngine;
using System.Collections;

public class Select3 : MonoBehaviour
{
float speed = 0;

void Start () 
{

}

void Update () 
{
	transform.Rotate(0, 0, Time.deltaTime*speed);      

	Debug.Log (gameObject.transform.rotation.z);       

	Debug.Log (gameObject.transform.rotation.z *180);  

	if (Mathf.Abs(gameObject.transform.rotation.z)*180 >= 179.995)  
	{
		speed = 0; 
	}
}

void OnMouseDown()
{
	speed = 100; 

}

}

void Start () {

}

void Update () {
	
	alpha += speed ;
	alpha = Mathf.Clamp(alpha, 0, 1) ;
	
	transform.rotation.eulerAngles.z = Mathf.Lerp(0, 180, alpha) ;
}

void OnMouseDown(){
	speed*=-1 ;
}