Question: using python checking to accept only integers between 1 and 5 (inclusive). When an allowed number is entered, it returns that number. The following example

using python
using python checking to accept only integers between 1 and 5 (inclusive).
When an allowed number is entered, it returns that number. The following
example shows the expected wording and formatting: 1>> [evaluate Lab1_JC.py] 2> get_choiceO

checking to accept only integers between 1 and 5 (inclusive). When an allowed number is entered, it returns that number. The following example shows the expected wording and formatting: 1>> [evaluate Lab1_JC.py] 2> get_choiceO Select option (1 to 5 ): a Invalid option. Please enter a number between 1 and 5:a Invalid option. Please enter a number between 1 and 5:? Invalid option. Please enter a number between 1 and 5: Invalid option. Please enter a number between 1 and 5:3.4 Invalid option. Please enter a number between 1 and 5:0 Invalid option. Please enter a number between 1 and 5:6 Invalid option. Please enter a number between 1 and 5:2 2 2) [35 marks] Write a function called get_input that accepts an iterable object (a list of ordered elements) named iterable as its parameter and returns a 3 -tuple. This function prompts the user for the following three values: (a) the letter ' A ' or ' D ', which will indicate ascending or descending (respectively), (b) an integer between 0 and the number of items in iterable, and (c) another integer between 0 and the number of items in iterable object. The function returns a 3-tuple: the first integer (as an integer), the second integer (as an integer), and either -1 (if the user entered 'D') or 1 (if the user entered ' A '). The function must perform error checking for all inputs and must accept both lower and uppercase characters for the first question. 3) [35 marks] Write a function called loops that accepts four arguments: (a) an integer named start, (b) an integer named stop, (c) an integer named step, and (d) an iterable object (a list of ordered elements) named iterable. This function returns None. The function must inspect the step value and swap start and st op values so that it always produces a non-empty sequence of numbers, i.e. if the value of step is positive, the value of start must be less than the value of stop. If start is greater than stop - switch the values. It must first use a for loop to display the sequence of numbers horizontally and a while loop to display the sequence of numbers horizontally that includes the start and stop values. 4) [20 marks] Write a function named main that takes no parameters and returns None. This function displays a menu (see sample output for menu), gets a choice from the user, and executes that choice. Choice 1 will demonstrate the functions for loops. The user should be asked for a choice until ' 5 ' is entered, which displays 'Goodbye' and terminates. Within this function, create the following iterable object: iterable=[0,1,2,3,4,5,6,7,8,9,10] See next page for sample output of main. [evaluate Lab1_JC.py] main() Options: 1. Demo 'for' and 'while' loops 2. Display 'Option 2 selected' 3. Display 'Option 3 selected' 4. Display 'Option 4 selected' 5. Quit Select option ( 1 to 5 ): 2 Option 2 selected Options: 1. Demo 'for' and 'while' loops 2. Display 'Option 2 selected' 3. Display 'Option 3 selected' 4. Display 'Option 4 selected' 5. Quit Select option ( 1 to 5 ): 1 Enter ' A ' (for ascending) or ' D ' (for descending): a Enter an index: 2 Enter another index: 8 Output for 'for' loop: 2345678 Output for 'while' loop: 2345678 Options: 1. Demo 'for' and 'while' loops 2. Display 'Option 2 selected' 3. Display 'Option 3 selected' 4. Display 'Option 4 selected' 5. Quit Select option ( 1 to 5 ): 5 Goodbye

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!