Question

In: Computer Science

(Python)####But, what if we need just a sequence without brackets, i.e., we want to have ####1,...

(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.
##

Solutions

Expert Solution

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=', ')

##


Related Solutions

The table below shows the stock (i.e. what you have) and final (i.e. what you want)...
The table below shows the stock (i.e. what you have) and final (i.e. what you want) concentrations/quantities for a 25 μl PCR. Item Stock Concentration Amount wanted per 25μl PCR Forward Primer 10 μM 0.4 μM Reverse Primer 10 μM 0.4 μM Buffer (contains dNTPs, polymerase, MgCl2) 2X concentrate 1X DNA 25 ng/μl 25 ng/μl *Use the table to answer the following questions and please show how you got the answer. Thank you! 1. For each 25 μl reaction, what...
Python. Write a function last_occur(s, e) that takes as inputs a sequence (i.e., a string or...
Python. Write a function last_occur(s, e) that takes as inputs a sequence (i.e., a string or list) s and an element e, and that calls itself recursively to find and return the index of the last occurrence of e in s. If s is a string, e will be a single-character string; if s is a list, e can be any value. Don’t forget that the index of the first element in a sequence is 0. Important notes: If e...
What we want the program to do: We need to write a program, in Java, that...
What we want the program to do: We need to write a program, in Java, that will let the pilot issue commands to the aircraft to get it down safely on the flight deck. The program starts by prompting (asking) the user to enter the (start) approach speed in knots. A knot is a nautical mile and is the unit used in the navy and by the navy pilots. After the user enters the approach speed, the user is then...
I dont know how to make de bruijn sequence in python. We have to print output...
I dont know how to make de bruijn sequence in python. We have to print output by following this step. 1.start with a string of n consecutive zeroes 2.append 1 to the end of the string if the n-digit suffix that would be formed this way has not already appeared in the sequence; otherwise a 0 is appended to the end of the string. 3.repeat step 2 until the length of the sequence equals 2 **n For instance, when we...
I just want this answer to be in simple and easy words without missing the key...
I just want this answer to be in simple and easy words without missing the key words, to be easy for memorizing and understanding for my test.. please help We, as engineers, do not injure directly or indirectly the prospect of another engineer. In the same time, we shall be faithful and honest with our client and employer. In discharging our duty and carrying our works, we shall bear in mind that fair and honest dealing with all parties is...
Write the following Python script: Problem Statement We want to know how many different people have...
Write the following Python script: Problem Statement We want to know how many different people have eaten at a restaurant this past week. The parameter meals has strings in the format "name:restaurant" for a period of time. Sometimes a person eats at the same restaurant often. Return the number of different people who have eaten at the eating establishment specified by parameter restaurant. For example, "John Doe:Moes" shows that John Doe ate one meal at Moes. Write function howMany that...
Consider an infinite sequence of positions 1, 2, 3, . . . and suppose we have...
Consider an infinite sequence of positions 1, 2, 3, . . . and suppose we have a stone at position 1 and another stone at position 2. In each step, we choose one of the stones and move it according to the following rule: Say we decide to move the stone at position i; if the other stone is not at any of the positions i + 1, i + 2, . . . , 2i, then it goes to...
We decided that we need to specify the type of retirement income we want and make...
We decided that we need to specify the type of retirement income we want and make plans to accomplish our goal. Our goal is to plan for 25 years of retirement, at $150,000 per year, but we want to receive the $150,000 at the beginning of each year of our retirement. So, to reach our objective, for the next 30 years, we need to set aside the right amount of money as an annual constant contribution into a retirement fund...
What is an escape sequence? Give an example in Python, and describe what it does. What...
What is an escape sequence? Give an example in Python, and describe what it does. What Python function is used to determine the length of Python objects such as lists, tuples and string literals? For the string literal “Bjorggson”, show by Python code example how to obtain the fourth character of that string. Show by code example in Python how to concatenate two strings and assign the result to a variable. Declare a Python list named famfri with the first...
1) Is it possible to have zero pollution? If it is possible, would we want to...
1) Is it possible to have zero pollution? If it is possible, would we want to achieve zero pollution? Explain. (4-6 sentences) 2) Consider activities like smoking or talking on a cell phone while driving. What types of externalities are associated with these examples, and what do you think should be done about these behaviors (if anything)? (4-6 sentences)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT