Python Forum
reset on inactivity (building a morse decoder)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reset on inactivity (building a morse decoder)
#4
Indentation is how Python blocks code. Other languages use start and end markers, but in python you indicate which code is inside an if statement by indentation. The code below is a valid if/else.
while True:
    key.wait_for_press(120)
    if not key.is_pressed():
        os.system("clear") # Linux - OSX
        print("Welkom bij de morse emulator van maritiem centrum Ameland")
    else:
        key_down_time = time.time() #record the time when the key went down
        tone_obj.play(-1) #the -1 means to loop the sound
        key.wait_for_release()
This code complains about the "else:" because then indentation of the "print" command is an end marker for the "if" statement
while True:
    key.wait_for_press(120)
    if not key.is_pressed():
        os.system("clear") # Linux - OSX
    print("Welkom bij de morse emulator van maritiem centrum Ameland")
    else:
        key_down_time = time.time() #record the time when the key went down
        tone_obj.play(-1) #the -1 means to loop the sound
        key.wait_for_release()
The equivalent C code is:
while (1)
{
    wait_for_press(key, 120)
    if (!is_pressed(key))
    {
        os_system_clear()
    }
    print("Welkom bij de morse emulator van maritiem centrum Ameland");
    else
    {
        key_down_time = time()
        tone_obj_play(-1)
        wait_for_release(key)
    }
Reply


Messages In This Thread
RE: reset on inactivity (building a morse decoder) - by deanhystad - Apr-15-2020, 12:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  (python) Can i get some help fixing a English to Morse translator? Pls AlexPython 8 3,403 Dec-03-2024, 10:21 AM
Last Post: skylartyler
  How can i fix json.decoder.JSONDecodeError ? JgKSuperstar 9 7,267 Oct-30-2021, 11:23 PM
Last Post: JgKSuperstar
  How to fix bugs in Morse alphabet code? dokipo 10 4,950 Oct-26-2021, 06:43 PM
Last Post: deanhystad
  How to reset row value in pandas Mekala 0 2,054 Sep-19-2020, 09:36 AM
Last Post: Mekala
  coding a decoder... Popkhorn 2 2,863 May-28-2020, 07:26 AM
Last Post: Popkhorn
  Reset a variable mln4python 4 10,630 Aug-19-2019, 08:28 AM
Last Post: mln4python
  UTF-8 decoder reports bad byte that is not there Skaperen 0 2,987 Oct-11-2018, 04:46 AM
Last Post: Skaperen
  MP4 decoder jdewk 4 7,107 Jan-13-2018, 10:02 PM
Last Post: jdewk
  JSON Decoder issue Cronax3 2 10,732 Sep-13-2017, 09:23 AM
Last Post: Cronax3

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020