Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • AI for Simple Python Scripts

AI for Simple Python Scripts

Asking for Better


Did You Know: Good vs Better

ChatGPT wrote a functioning script that mostly “does the job.” However it is not as easy to understand as it could be, and it takes more memory than examples from other micro:bit tutorials.  For example, it could have used Image.HEART and Image.HEART_Small instead of creating the heart_full and heart_empty custom images.  Also, instead of importing the time module, it could just use sleep(500). All of these changes would make the code easier to read and understand, while using less memory. A better script.


Your Turn: Asking for Easy to Read Code

User

Why not use Image.HEART and Image.HEART_SMALL instead?  Also, instead of importing time, just use sleep in milliseconds.

ChatGPT

Certainly! Here’s an updated version of the program using Image.HEART and Image.HEART_SMALL, and using the sleep function in milliseconds:

from microbit import *

while True:
    display.show(Image.HEART)
    sleep(500)  # Display the full heart for 500 milliseconds (0.5 seconds)
    display.show(Image.HEART_SMALL)
    sleep(500)  # Display the small heart for 500 milliseconds (0.5 seconds)

This program achieves the same beating heart effect using the built-in heart images and the sleep function with a delay of 500 milliseconds. Feel free to customize the timings or make any other adjustments as needed!

 

User

That looks better.

ChatGPT

I’m glad you found it better! If you have any more questions or if there’s anything else I can help you with, feel free to ask. Happy coding with your micro:bit!

  • Enter the script into the micro:bit Python Editor.
  • Run the script by clicking the Send to micro:bit button.
  • Did it work as ChatGPT described, by displaying beating heart?
  • Was the result identical to the previous AI-generated heartbeat script from the last page?

 


Printer-friendly version
Asking for More
Prev
Try an Existing Tilt Compass
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress