def get_response(self, data={}): # Parse the options and shuffle them, for variety. options = self.choices random.shuffle(options) # Loop until the user selects the correct answer. while True: # Begin by printing the menu with numerical identifiers. for i, option in enumerate(options): colors.print_option("%d: %s" % (i + 1, option)) # Get the user's choice and try to return the relevant # answer, catching failures and restarting as appropriate. # Note that invalid input restarts the loop here, but an # incorrect answer will restart the loop outside of the # scope of the function. This allows for grading. # XXX: Try to match strings to choices, too. try: colors.print_inst("Select one of the numbered choices: ", end="") choice = int(input()) - 1 return options[choice] except (ValueError, IndexError): colors.print_help("Please pick an integer between 1 and %d" % len(options)) continue
def get_response(self, data={}): # Parse the options and shuffle them, for variety. options = self.choices random.shuffle(options) # Loop until the user selects the correct answer. while True: # Begin by printing the menu with numerical identifiers. for i, option in enumerate(options): colors.print_option("%d: %s" % (i+1, option)) # Get the user's choice and try to return the relevant # answer, catching failures and restarting as appropriate. # Note that invalid input restarts the loop here, but an # incorrect answer will restart the loop outside of the # scope of the function. This allows for grading. # XXX: Try to match strings to choices, too. try: colors.print_inst("Select one of the numbered choices: ", end="") choice = int(input())-1 return options[choice] except (ValueError, IndexError): colors.print_help( "Please pick an integer between 1 and %d" % len(options)) continue
def menu(): print("\n") print("Welcome to the course menu! If you like to exit to the main menu at any point, press Ctrl+D or enter '0'. \n") print("You have the following courses to choose from: \n") path = str(import_course_path.get_path()) # # print(filter(os.path.isdir, os.listdir(path))) courses = next(os.walk( os.path.join(path,'.')))[1] courses.remove("__pycache__") for index, course in enumerate(courses): colors.print_option("%d: %s" % (index + 1, course)) print("\n") try: course_select = input("| -- Select a course: ") print("\n") except EOFError: print("Returning to the main menu.. \n") return try: course_select = int(course_select) except ValueError or ModuleNotFoundError: colors.print_err("No course. Returning to Course menu.. \n") menu() if type(course_select) == int: if course_select == 0: print("Returning to the main menu.. \n") return try: course_select = courses[course_select - 1] except IndexError or ModuleNotFoundError: colors.print_err("No course. Returning to Course menu.. \n") menu() moduleNames = 'courses.'+ str(course_select) pkg = '.initialize_lesson' m = importlib.import_module(moduleNames+pkg) # print(m) #print(globals()) data = m.get_data() # print(m.pd.DataFrame()) # print("| Choose from the following commands: ('run', 'info', 'create', 'test') \n") # command = input("| Enter a command for the course: ") main(m, data, parse(["run", os.path.join(path,course_select)]))
def swirl(): print("\n") colors.print_option("| Welcome to swirlpy! What can I call you? \n") user_name = input("Please enter your name: ") print("\n") print("| Thanks", user_name + "!", "Lets cover some basic commands in swirlpy\n") print( "| Whenever you see '...', that means you should press Enter when you are ready. \n" ) print("... <- your cue to press Enter to continue \n") input("") while True: print( "\n Welcome to the main menu of Swirlypy! You have the following options: \n" ) colors.print_option( "| -- Typing learn() allows you to start a course. \n") colors.print_option("| -- Typing bye() causes Swirlypy to exit. \n") colors.print_option( "| -- Typing menu() displays the main menu again. \n") user_input = input("Enter your choice: ") if user_input == "bye()": print("\n") colors.print_exit("Leaving Swilypy now..Bye! \n") exit() elif user_input == "learn()": menu() elif user_input == "menu()": continue
def menu(self): """Prints a menu containing all of the lessons in the course, along with their index.""" for index, lesson in enumerate(self.lessonnames): colors.print_option("%d: %s" % (index + 1, lesson))
def menu(self): """Prints a menu containing all of the lessons in the course, along with their index.""" print("\nPress Ctrl+D at any point to exit to the menu.") for index, lesson in enumerate(self.lessonnames): colors.print_option("%d: %s" % (index + 1, lesson))