How to add pause/resume keys in python scripts in mac osx -
i wrote python script helping kids memorize chemical elements. there 'for' loop lasts minutes , add 'pause' , 'resume' functions pressing keys (as needed), in case kids want take break. posts mentioned "ctrl+z", stops script in terminal. others suggest using raw_input, needs press keys in every cycle of 'for' loop. script below:
import os import random import time name = 'eric' element_table = {'h':'hydrogen', 'he':'helium', 'c':'carbon', 'n':'nitrogen', 'o':'oxygen', 'f':'fluorine', 'ne':'neon', 'mg': 'magnesium', 'na':'sodium', 'k':'potassium', 'ca':'calcium','fe':'iron', 'cu':'copper', 'ag':'silver', 'au':'gold', 'hg':'mercury', 'al':'aluminum', 'i':'iodine', 'ni':'nickel', 'br':'bromine', 'cr':'chromium', 'si':'silicon', 'ba':'barium', 'mn':'manganese', 'zn':'zinc', 'p':'phosphorus', 's':'sulfur', 'cl':'chlorine', 'sn':'tin'} temp_table = element_table os.system("say hello %s. let practice element-to-symbol of periodic element table" % (name)) while (temp_table): rand_key = random.choice(temp_table.keys()) time.sleep(2) os.system("say symbol element of %s" % temp_table[rand_key]) time.sleep(1) time.sleep(7) os.system("say time up. answer " ) k in range(0, len(rand_key)): os.system("say %s" % rand_key[k]) time.sleep(0.4) time.sleep(2) del temp_table[rand_key] if (temp_table): os.system("say next question") os.system("say practice over") time.sleep(0.5) os.system(" see next time")
Comments
Post a Comment