In: Computer Science
>>python
Question: Create program which acquires an integer in the range
1-17, and then outputs a times table from that acquired figure.
Function should print times table and another function which
acquires and returns the ranged integer. Therefore they are
distinct functions.
Specific details to include:
You can also in the central area of the code script allocate a value which is returned aside a function to a variable.(For example table=yourchoiceinteger(1,17).) Therefore that table which is the variable will be used as parameter when you name that function it'll output specific timetable.
CODE
#function yourChoiceInteger to acquire an integer in the range 1 - 17
def yourChoiceInteger():
        #loop to read input from user
        while True:
                #prompt for integer in the range 1 - 17
                integer = int(input("Enter an integer in the range 1 - 17: "))
                
                #if input is valid
                if integer >= 1 and integer <= 17:
                        #returns input
                        return integer
                #otherwise
                else:
                        #prints error message
                        print("Please enter a valid integer")
                        
#function printTimesTable() to print times table
def printTimesTable(table):
        #loop to print times table
        for i in range(1, 11):
                #printing each row in table
                print(i, "*", table, "=", i * table)
                
#main
if __name__ == "__main__":
        #calling yourChoiceInteger
        table = yourChoiceInteger()
        
        #calling printTimesTable
        printTimesTable(table)
        
OUTPUT

CODE SCREEN SHOT
