'''
(a) Output the times-tables (from 1 to 12) for whichever number the user requests. For example, if the user enters 3, your output should be: (1K)
1 x 3 = 3
2 x 3 = 6
...
12 x 3 = 36
Extension:
(b) Allow the user to specify the start and end to the table (e.g., 4 to 15); (2K)
(c) Allow the user to specify the step size (e.g., by 3 is 4, 7, 10, 13). (2T)
'''
"""
let's create a function, the result of which is printing line by line
times-tables
function arguments:
elem - table item value
start_tab -the default starting index of the table is 1
end_tab -default final table index is 12
step_tab -default table step 1
"""
def time_tab(elem,start_tab=1,end_tab=12,step_tab=1):
for item in range(start_tab,end_tab+1,step_tab):
print(f'{item} * {elem} = {item*elem}')
#task a)
element = int(input('Enter the value of the table element '))
time_tab(element)
#task b)
element = int(input('Enter the value of the table element '))
start_ind = int(input('Enter the starting index of the table '))
finish_ind = int(input('Enter the last index of the table '))
time_tab(element, start_ind, finish_ind)
#task c)
element = int(input('Enter the value of the table element '))
start_ind = int(input('Enter the starting index of the table '))
finish_ind = int(input('Enter the last index of the table '))
step_ind = int(input('Enter table step '))
time_tab(element, start_ind, finish_ind, step_ind)
Comments
Leave a comment