Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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 doesnt 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

Why is the structure of the compensation function important?

Answered: 1 week ago