Question

It is done in python, can you please explain what does the part of the code...

It is done in python, can you please explain what does the part of the code in bold do?

print("Point should be in format (x,y)")
p1 = input("Enter point 1: ")
p2 = input("Enter point 2: ")
x1 = int(f(p1).split(",")[0])
y1 = int(f(p1).split(",")[1])
x2 = int(f(p2).split(",")[0])
y2 = int(f(p2).split(",")[1])
slope = (y2-y1)/(x2-x1)
print("Slope =",slope)

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# i am illustrating below example using the inputs below
# 2,3  (this is entered on first line)
# 4,5  (this is entered on second line)


print("Point should be in format (x,y)")

# it reads the complete input line as string: "2,3"
p1 = input("Enter point 1: ")

# it reads the complete input line as string: "4,5"
p2 = input("Enter point 2: ")

# Now sure what is f function doing here, probably taking a string and 
# trimming the space or paranthesis at starting and space.

# Now input is in form of 2,3
# when we split it by comma, we get a list ['2', '3']
# both elements are still string.. [0] means take the first element
# so '2' in string form is picked.. The int('2') will give 2
x1 = int(f(p1).split(",")[0])
y1 = int(f(p1).split(",")[1])
x2 = int(f(p2).split(",")[0])
y2 = int(f(p2).split(",")[1])


# so, x1 = 2, y1 = 3, x2=4, y2=5

# now sloe is calculated
slope = (y2-y1)/(x2-x1)
print("Slope =",slope)
Add a comment
Know the answer?
Add Answer to:
It is done in python, can you please explain what does the part of the code...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Intro to Python: Q1: Bonnie is writing a Python program for her math class so she can check her answers quickly. She is...

    Intro to Python: Q1: Bonnie is writing a Python program for her math class so she can check her answers quickly. She is having some difficulties, however, because when she enters values like 3.5 or 2.71 her program throws an error. She has heard of your expertise in Python and asks for your help. What error is being thrown and how can she fix the program to accept values like 3.5 or 2.71? from math import sgrt def distance (coorl,...

  • Python = Modify this chapter's case study program (the c-curve) so that it draws the line...

    Python = Modify this chapter's case study program (the c-curve) so that it draws the line segments using random colors. code to amend: from turtle import Turtle def cCurve(t, x1, y1, x2, y2, level):    def drawLine(x1, y1, x2, y2):       """Draws a line segment between the endpoints."""       t.up()       t.goto(x1, y1)       t.down()       t.goto(x2, y2)    if level == 0:       drawLine(x1, y1, x2, y2)    else:       xm = (x1 + x2 + y1 - y2)...

  • Must be in Python 3.6 (please have a screen shot on the code) ex 2.14 :...

    Must be in Python 3.6 (please have a screen shot on the code) ex 2.14 : # Enter three points for a triangle x1, y1, x2, y2, x3, y3 = eval(input("Enter three points for a triangle: ")) # Compute the length of the three sides side1 = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ** 0.5 side2 = ((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 -...

  • INSTRUCTIONS: I NEED TO CREATE A PointApp PROGRAM THAT USES THE FOLLOWING API DOCUMENTATION. Below the...

    INSTRUCTIONS: I NEED TO CREATE A PointApp PROGRAM THAT USES THE FOLLOWING API DOCUMENTATION. Below the API Documentation is the code I submitted. However, the output is different for what they are asking. I am looking for someone to fix the code to print out the correct output and to add comments so I can have an idea in how the code works. PLEASE AND THANK YOU. API DOCUMENTATION: public class Point extends java.lang.Object The Point class is used to...

  • convert this python code to c++ code def sort(a,b): if a > b: return b,a else:...

    convert this python code to c++ code def sort(a,b): if a > b: return b,a else: return a,b def main(): set1 = input('Enter the first pair of integers: ') set2 = input('Enter the second pair of integers: ') set3 = input('Enter the third pair of integers: ') set1 = set1.split(',') set1_0 = int(set1[0]) set1_1 = int(set1[1]) set2 = set2.split(',') set2_0 = int(set2[0]) set2_1 = int(set2[1]) set3 = set3.split(',') set3_0 = int(set3[0]) set3_1 = int(set3[1])    print(sort(set1_0,set1_1)) print(sort(set2_0,set2_1)) print(sort(set3_0,set3_1))

  • how to make my code of python work probely my q is how to write a...

    how to make my code of python work probely my q is how to write a code to find the average actual water level, average error by using python and my program should be flexible where user can select the column no. If you can see in the main program, it asked which column to know the maximum or average, the column number is passed to the function. The function should look which column to do. #THIS PROGRAMMING IS ABLE...

  • The output should be "The distance is 0" (The expected). ==================== YOUR OUTPUT =====================                        

    The output should be "The distance is 0" (The expected). ==================== YOUR OUTPUT =====================                                                                                                               0001: Enter~the~x~coordinate~for~point~1:~0                                                                                                                          0002: Enter~the~y~coordinate~for~point~1:~0                                                                                                                          0003: Enter~the~x~coordinate~for~point~2:~0                                                                                                                          0004: Enter~the~y~coordinate~for~point~2:~0                                                                                                                          0005: The~distance~is~-nan    =================== MISMATCH FOUND ON LINE 0005: ===================                                                                                                 ACTUAL  : The~distance~is~-nan                                                                                                                                       EXPECTED: The~distance~is~0                                                                                                                                          ======================================================   #include <iostream> #include <iomanip> #include <string> using namespace std; float squareRoot(float s) { float xn; xn = s / 2.0; int counter = 1; while (counter <= 10) { xn = (xn + (s/xn))/2.0; counter = counter + 1; } return xn; } int...

  • C++ code for CIS054 Create a program that uses a function to determine the length of...

    C++ code for CIS054 Create a program that uses a function to determine the length of a line by inputting the X,Y coordinates of the line endpoints. Show the result with a precision of four decimal places. The function prototype is to be specified as follows:     double LengthOfLine (double X1, double Y1, double X2, double Y2); // returns length of line by using this code: #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main(int argc, char* argv[])...

  • python programming: Can you please add comments to describe in detail what the following code does:...

    python programming: Can you please add comments to describe in detail what the following code does: import os,sys,time sl = [] try:    f = open("shopping2.txt","r")    for line in f:        sl.append(line.strip())    f.close() except:    pass def mainScreen():    os.system('cls') # for linux 'clear'    print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")    print(" SHOPPING LIST ")    print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")    print("\n\nYour list contains",len(sl),"items.\n")    print("Please choose from the following options:\n")    print("(a)dd to the list")    print("(d)elete from the list")    print("(v)iew the...

  • Python 3 Can anyone make my Python code more readable, by breaking up the code into...

    Python 3 Can anyone make my Python code more readable, by breaking up the code into smaller chunks using functions. If a piece of code tries to do several things, it should be broken up into several different functions. print("chatbot: Hello, I am chatbot. What is your name?") name = input("") print("chatbot: Nice to meet you "+name+". Tell me now, what is your age?") age = int(input("")) if age >= 16 and age <= 25: print("We are the same age!...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT