![]() |
Help! Program in python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Help! Program in python (/thread-40884.html) |
Help! Program in python - lana - Oct-08-2023 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 ![]() ![]() ![]() ![]() 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." RE: Help! Program in python - Pedroski55 - Oct-08-2023 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") RE: Help! Program in python - lana - Oct-08-2023 (Oct-08-2023, 05:52 PM)Pedroski55 Wrote: Help?? An emergency?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!!!!! RE: Help! Program in python - Pedroski55 - Oct-08-2023 You can do this with decimal point numbers: num = 1.123456789 print(f'number is {num:.2f}')
RE: Help! Program in python - ICanIBB - Oct-11-2023 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") |