Use Print once in IF

Hi, Hope all is good. i’m hoping someone can point me in the right direction, I’ve been trying out adding circuits to a raspberry pi using a tutorial on raspi.tv and one of the questions is to have the print statement only display once on change instead of continuous and i’m having a problem on how to do this , I’ve added the code i have if someone could please find the time to check what i’m doing wrong or missing out, thank you.

import RPi.GPIO as GPIO
from time import sleep		#this lets us have a time delay
GPIO.setmode(GPIO.BCM)		#set up BCM GPIO numbering
GPIO.setup(25, GPIO.IN)		#set GPIO25 as input(button)
GPIO.setup(24,GPIO.OUT)		#set GPIO24 as output(LED)
state = True
try:
    while True:#this will carry on until you hit CTRL C
        
            if GPIO.input(25):#if port 25==1
                if state:
                   print("Port25 is 1/High/True - LED ON")
                   GPIO.output(24,1) 							# set port/pin value
                   state = True              
        
        
            else:
                if state:
                    print("Port 25 is 0/LOW/False")
                    GPIO.output(24,0)							# set port/pin value to 0/LOW/False
                    sleep(0.1)										# wait 0.1 seconds
                    state = True
finally:												# this block will run no matter how the try block exits
    GPIO.cleanup()										# clean up aftr yourself

Hint: Think seems wrong. I’ll let you review.

This seems to work, not sure if its good practice though…which i’m trying to develop.

import RPi.GPIO as GPIO
from time import sleep		#this lets us have a time delay
GPIO.setmode(GPIO.BCM)		#set up BCM GPIO numbering
GPIO.setup(25, GPIO.IN)		#set GPIO25 as input(button)
GPIO.setup(24,GPIO.OUT)		#set GPIO24 as output(LED)
state = False
try:
    while True:#this will carry on until you hit CTRL C
        
            if GPIO.input(25):#if port 25==1
                if state:
                   print("Port25 is 1/High/True - LED ON")
                   GPIO.output(24,1) 							# set port/pin value
                   state = False
                   
        
        
            else:
                if not state:    
                    print("Port 25 is 0/LOW/False")
                    GPIO.output(24,0)							# set port/pin value to 0/LOW/False
                    sleep(0.1)										# wait 0.1 seconds
                    state = True
finally:												# this block will run no matter how the try block exits
    GPIO.cleanup()										# clean up aftr yourself

Issue is if the button is pressed at startup it wont detect…so its not right

Well, if GPIO.input(25) returns a true value and state is False initially, it won’t print the message.