# =================================================================== # command line user interface functions # =================================================================== import os import sys import platform # ------------------------------------------------------------------- # ----running Python3? # ------------------------------------------------------------------- def running_python3(): if sys.version_info[0] == 3: return True return False # ------------------------------------------------------------------- # ---- prompt the user for input # ------------------------------------------------------------------- def get_user_input(prompt): return input(prompt).strip() # ------------------------------------------------------------------- # ---- pause program # ------------------------------------------------------------------- def pause(): print() get_user_input('Press enter to continue ') # ------------------------------------------------------------------- # ---- clear the terminal screen (window) # ------------------------------------------------------------------- def clear_screen(): if platform.system() == 'Linux': os.system('clear') elif platform.system() == 'Windows': os.system('clear') else: os.system('cls') # ------------------------------------------------------------------- # ---- Function: convert a string to a float # ------------------------------------------------------------------- def is_float(s): try: n = float(s) return (True,n) except: return (False,0.0) # ------------------------------------------------------------------- # ---- Function: convert a string to an int # ------------------------------------------------------------------- def is_int(s): try: n = int(s) return (True,n) except: return (False,0) # ------------------------------------------------------------------- # ---- is a number (int, float, scientific notation) # ------------------------------------------------------------------- def is_a_number(s): x,n = is_int(s) if x: return True x,n = is_float(s) if x: return True return False