In: Computer Science
(Python)####But, what if we need just a sequence without
brackets, i.e., we want to have
####1, 2, 3, 4,... and not [1, 2, 3, 4, 5, ...]?
####We can do this:
##print(*accum, sep=", ") ## *accum 'unpacks' the list accum.
Ask for the left and the right range bounds with input:
##
##leftB = int(input('Enter the left bound: '))
##rightB = int(input('Enter the right bound: '))
## and if (rightB - leftB) is odd then print the list of the
numbers in this range,
## if (rightB - leftB) is even then print just sequence (no
brackets []) of the numbers in this range.
##
If you have any doubts, please give me comment...
####1, 2, 3, 4,... and not [1, 2, 3, 4, 5, ...]?
####We can do this:
##print(*accum, sep=", ") ## *accum 'unpacks' the list accum.
# Ask for the left and the right range bounds with input:
##
leftB = int(input('Enter the left bound: '))
rightB = int(input('Enter the right bound: '))
# then print the list of the numbers in this range,
if (rightB - leftB)%2==1:
accum = [i for i in range(leftB, rightB+1)]
print(*accum, sep=', ')
# then print just sequence (no brackets []) of the numbers in this range.
## if (rightB - leftB) is even
if (rightB - leftB)%2==0:
accum = [i for i in range(leftB, rightB+1)]
print(*accum, sep=', ')
##