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 10:00
Hey i just logged on and one of the moderators deleted a bunch of my answers to questions, even though the answers were right and the people it doesn't make sense but if anyone wants to talk about anything just message me lol (this is super random lol)
Answers: 1
question
Computers and Technology, 24.06.2019 00:30
Match the sentence fragment in the first column with the appropriate ending in the second column. a little per favore?
Answers: 1
question
Computers and Technology, 24.06.2019 02:40
Has anyone seen my grandma shes been gone for 4 years already
Answers: 1
question
Computers and Technology, 24.06.2019 23:40
Which slide should you change so it reflects om all sides of your presentation
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
Mathematics, 20.05.2021 19:10
question
History, 20.05.2021 19:10
Questions on the website: 13722361