Quantcast
Viewing all articles
Browse latest Browse all 4867

Python • Re: Used to work now doesnt

i ran your code through chatgpt and it spit out this to correct errors.

Code:

import gpiozerofrom gpiozero import Button, OutputDeviceimport time# Length of time to water manually (in minutes)manual_time = 2manual_time2 = 5# Initialize buttonbutton = Button(6)# Manual Watering Functiondef manual(water_count, valve_pin, watering_time):    valve = gpiozero.OutputDevice(valve_pin)    if not valve.value and water_count < 1:        valve.on()        time.sleep(1)        time.sleep(watering_time * 60)        valve.off()        water_count += 1    else:        print("Garden already watered today")# Listen for Button Pressdef button_pressed():    global waterCount, waterCount2    manual(waterCount, 26, manual_time)    manual(waterCount2, 4, manual_time2)button.when_pressed = button_pressedtry:    while True:        time.sleep(1)  # Keep the program runningexcept KeyboardInterrupt:    pass  # Handle Ctrl+C gracefullyfinally:    gpiozero.close_all()  # Clean up GPIO resources
Sigh. ChatGPT.

What were the errors? How do you know that it corrected the errors? If you knew what the errors were, why didn't you correct them yourself? How do you know it didn't introduce errors?
Image may be NSFW.
Clik here to view.
:lol:

didn't think to copy the report/explanation

but if you must know, copy the original & head on over to chatgpt
In my option the explanations for the changes are far more useful than the changes themselves. Is there a recommended way to ask chatgpt to audit code and correct errors?

I've never done that before.

Statistics: Posted by ejolson — Fri Jun 07, 2024 5:31 am



Viewing all articles
Browse latest Browse all 4867

Trending Articles