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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 00:40, mcfancei
Reading characters and strings from the keyboard: consider the following c++ program 1. #include 2. #include 3. using namespace std; 4. mystring1 5. 6. int main() 7. { 8. 9. string mystring1, mystring2; mychar1 10. 11. 12. char mychar1, mychar2; 13. 14. cout< < "enter a string: "; mychar2 15. 16. cin> > mystring1; // 17. cin. get(mychar1); 18. cin> > mychar2; 19. getline(cin, mystring2); mystring2 20. 21. 22. cout<
Answers: 1
image
Computers and Technology, 22.06.2019 07:30, akluke6059
Events and conditions that happen within an organization that are somewhat easier to deal with when responding to change are called
Answers: 1
image
Computers and Technology, 22.06.2019 19:00, trintrin227
In he example code, what does the title attribute create? a tool tip an element a source a markup
Answers: 1
image
Computers and Technology, 23.06.2019 01:50, rhonda45801
Free points just awnser this. what should i watch on netflix
Answers: 2
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 in other subjects:

Konu
Mathematics, 05.01.2021 04:40
Konu
Engineering, 05.01.2021 04:40
Konu
Chemistry, 05.01.2021 04:40
Konu
Computers and Technology, 05.01.2021 04:40
Konu
Arts, 05.01.2021 04:40
Konu
Mathematics, 05.01.2021 04:40