Advertisement
florin2040

point inside rectangle

Apr 5th, 2020
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.22 KB | None | 0 0
  1. '''
  2. Where is the code. What I missing? I receive 92% from 100 with both variants.
  3.  
  4. Write a program to check if a point {x, y} is on some of the sides of a rectangle {x1, y1} – {x2, y2}.
  5. Input
  6. The input comes from the console and it consists of 6 rows, introduced from the user:
  7. real numbers x1, y1, x2, y2, x and y (it will be always true that x1 < x2 and y1 < y2).
  8.  
  9. Output
  10. If the point lies on one of the rectangle's sides:
  11.    Print "Border"
  12. If the point does NOT lie on a side:
  13.    Print "Inside / Outside"
  14. Example
  15. Input           Output         Input             Output
  16. 2           Inside / Outside    2                   Border
  17. -3                             -3
  18. 12                              12
  19. 3                               3
  20. 8                               12
  21. -1                              -1
  22. * Hint: use one or more conditional if statements with logical operations.
  23. A point {x, y} lies on aside of a rectangle {x1, y1} – {x2, y2}, if one of the specified conditions is fulfilled:
  24.    x equals x1 or x2 and at the same time y is between y1 and y2
  25.    y equals y1 or y2 and at the same time x is between x1 and x2
  26. You can check the conditions above using one more complicated if-else construction or using
  27. few more simple conditional statements or nested if-else statements.
  28. '''
  29. x1=float(input())
  30. y1=float(input())
  31. x2=float(input())
  32. y2=float(input())
  33. x=float(input())
  34. y=float(input())
  35. if x1 == x and y1 < y < y2:
  36.     print("Border")
  37. elif x2 == x and y1 < y < y2:
  38.    print("Border")
  39. elif y1 == y and x1 < x < x2 :
  40.     print("Border")
  41. elif y2 == y and  x1 < x < x2:
  42.     print("Border")
  43. else:
  44.     print ("Inside / Outside")
  45. '''
  46. x1=float(input())
  47. y1=float(input())
  48. x2=float(input())
  49. y2=float(input())
  50. x=float(input())
  51. y=float(input())
  52. if x1 == x :
  53.    if y1 < y < y2:
  54.        print("Border")
  55.    else:
  56.        print ("Inside / Outside")
  57. elif x2 == x :
  58.    if y1 < y < y2:
  59.        print("Border")
  60.    else:
  61.        print ("Inside / Outside")
  62. elif y1 == y :
  63.    if x1 < x < x2:
  64.        print("Border")
  65.    else:
  66.        print ("Inside / Outside")
  67. elif y2 == y :
  68.    if x1 < x < x2:
  69.        print("Border")
  70.    else:
  71.        print ("Inside / Outside")
  72. else:
  73.    print("Inside / Outside")
  74. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement