Python Forum
Help! Program in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help! Program in python
#1
Sad 
Write a program that determines whether a point falls on
given coordinates into the shaded area. Points on the border
belong to the area. Obtain the necessary parameters from the figure.
Output the result of the program as a text message:
It hits, it doesn't hit. The tasks is in the files. Can anyone please explain how to do it, otherwise nothing is clear Cry Huh Confused . And if anyone can, please do at least one task. Sorry for my poor eng Cry

Description of the algorithm
1. Enter the coordinates of the point (x, y) and convert the values to float type.
2. Check to see if the point falls within the specified area.
3. Output the result in the form: "Point x, y falls within the area." and "Point"
x, y does not fall within the scope."

Description of input and output data
Input data - point coordinates entered by the user. Type
data and representation accuracy are not specified in the problem. Let's install
real type (float).
Output data - messages, in text form, about a hit or
the point does not fall within the specified area.

Program listing
from math import *
flag = 0
print('Enter the X and Y coordinates for the point:')
x = float(input('X='))
y = float(input('Y='))
if (x < -1) or (x > 4):
flag = 0 #False
if ((x>=-1) and (x<1) and (y>=2*x+2)
and (y<=x**3-4*x**2+x+6) or (x>=1)
and (x<=4) and (y>=x**3-4*x**2+x+6)and (y<=2*x+2)):
flag = 1
else:
flag = 0
print("Point X={0: 6.2f} Y={1: 6.2f}"
.format(x, y), end=" ")
if flag:
print("hits", end=" ")
else:
print("doesn't hit", end=" ")
print("to area."
buran write Oct-08-2023, 04:52 PM:
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.

Attached Files

Thumbnail(s)
   

.pdf   111.pdf (Size: 266.27 KB / Downloads: 89)
.pdf   222.pdf (Size: 140.72 KB / Downloads: 105)
Reply
#2
Help?? An emergency?

You don't need the module math for this!

Something like this maybe?? I don't really understand this number formatting!

print('Enter the X and Y coordinates for the point:')
x = float(input('Enter X = '))
y = float(input('Enter Y = '))
if x < -1 or x > 4:
    flag = 0 #False
# complicated elif hard to understand 
elif x>=-1 and x<1 and y>=2*x+2 and y<=x**3 - 4*x**2+x+6 or x>=1 and x<=4 and y>=x**3-4*x**2+x+6 and y<=2*x+2:
    flag = 1
else:
    flag = 0
print("Point X = {:.4f} Y={:.4f})".format( x, y ))
 
if flag:
    print(f"The point  {(x, y)} is within the graph borders")
else:
    print(f"The point {(x, y)} is outside of the area")
lana likes this post
Reply
#3
(Oct-08-2023, 05:52 PM)Pedroski55 Wrote: Help?? An emergency?

You don't need the module math for this!

Something like this maybe?? I don't really understand this number formatting!

print('Enter the X and Y coordinates for the point:')
x = float(input('Enter X = '))
y = float(input('Enter Y = '))
if x < -1 or x > 4:
    flag = 0 #False
# complicated elif hard to understand 
elif x>=-1 and x<1 and y>=2*x+2 and y<=x**3 - 4*x**2+x+6 or x>=1 and x<=4 and y>=x**3-4*x**2+x+6 and y<=2*x+2:
    flag = 1
else:
    flag = 0
print("Point X = {:.4f} Y={:.4f})".format( x, y ))

if flag:
    print(f"The point  {(x, y)} is within the graph borders")
else:
    print(f"The point {(x, y)} is outside of the area")
Yes, it's an emergency! hahaha I just urgently need to pass the laboratory test and the teacher didn’t explain anything.
"You don't need module math for this" Really? This is just what the teacher gave us as exemple... Anyway thank you so much for help!!!!!
Reply
#4
You can do this with decimal point numbers:

num = 1.123456789
print(f'number is {num:.2f}')
Output:
number is 1.12
Reply
#5
print('Enter the X and Y coordinates for the point:')
x = float(input('Enter X = '))
y = float(input('Enter Y = '))
if x < -1 or x > 4:
    flag = 0 #False
# complicated elif hard to understand 
elif x>=-1 and x<1 and y>=2*x+2 and y<=x**3 - 4*x**2+x+6 or x>=1 and x<=4 and y>=x**3-4*x**2+x+6 and y<=2*x+2:
    flag = 1
else:
    flag = 0
print("Point X = {:.4f} Y={:.4f}".format( x, y ))
  
if flag:
    print(f"The point  {(x, y)} is within the graph borders")
else:
    print(f"The point {(x, y)} is outside of the area")
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020