subject

How can I code this in Python with only if-statements? (Only allowed to use the built-in functions int(), float(), and str().)

def intervals_relation(A_start, A_end, B_start, B_end)

Description: The function checks whether intervals A and B have an overlap and returns a value that indicates what kind of overlap this is.

Parameters: A_start (int) and A_end (int) are the left and right limits of interval A, while B_start (int) and B_end (int) are the left and right limits of interval B respectively. All values are inclusive (i. e. intervals are closed from both ends). Parameters A_start and A_end are guaranteed to be in order (the same holds for parameters B_start and B_end), but this doesn’t mean that interval A is necessarily positioned before interval B.

Return value: If the two intervals do not overlap you return 0. If one is enclosed entirely by the other you return 1. If there is a partial overlap you return -1. The return value is always an int.

Examples:

intervals_relation(1,8,2,8) → 1

intervals_relation(3,7,-1,2) → 0

intervals_relation(4,5,-2,4) → -1

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 00:30
Quic which one of the following is the most accurate definition of technology? a electronic tools that improve functionality b electronic tools that provide entertainment or practical value c any type of tool that serves a practical function d any type of tool that enhances communication
Answers: 1
question
Computers and Technology, 23.06.2019 11:00
How should you specify box sizes on a web page if you want the boxes to vary according to the font size of the text they contain? a. in pixels b. in inches c. as percentages d. in em units
Answers: 2
question
Computers and Technology, 23.06.2019 22:30
The output voltage of a power supply is assumed to be normally distributed. sixteen observations are taken at random on voltage are as follows: 10.35, 9.30, 10.00, 9.96, 11.65, 12.00, 11.25, 9.58, 11.54, 9.95, 10.28, 8.37, 10.44, 9.25, 9.38, and 10.85
Answers: 1
question
Computers and Technology, 24.06.2019 07:00
Into what form does the barcode reader convert individual bar patterns?
Answers: 1
You know the right answer?
How can I code this in Python with only if-statements? (Only allowed to use the built-in functions i...
Questions
question
World Languages, 19.04.2021 22:00
Questions on the website: 13722367