CS_8151 - Unit 2 - Data, Expressions and Statements

Python interpreter and interactive mode; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence of operators, comments; modules and functions, function definition and use, flow of execution, parameters and arguments; Illustrative programs: exchange the values of two variables, circulate the values of n variables, distance between two points. Thanks to https://www.mathsisfun.com/algebra/distance-2-points.html

16 flashcards · Programming Languages · by kgashok

  1. Coordinate Geometry Terms Coordinate Geometry Definition - It is one of the branches of geometry where the position of a point is defined using coordinates. What are the Coordinates?

    What are the Coordinates? Coordinates are a set of values which helps to show the exact position of a point in the coordinate plane.

  2. Coordinate Plane Meaning - A coordinate plane is a 2D plane which is formed by the intersection of two perpendicular lines known as the x-axis and y-axis. What is the Distance Formula?

    What is the Distance Formula? It is used to find the distance between two points situated in A(x1,y1) and B(x2,y2)

  3. What is the most logical way to represent a cartesian point in Python? A. Use two variables, for e.g. x1 and y1 or x2 and y2 B. Use a single tuple variable C. None of the above

    Choice B. Tuple is the logical way of representing a point in Python.

  4. What is the syntax for defining a point (3, 4) as a tuple in Python? A. (3, 4) B. tuple(3, 4) C. Both the above are valid

    Choice C. (3, 4) and tuple(3, 4) are equivalent to each other.

  5. How can you unpack a tuple that represents a point?

    How do you unpack a tuple? If pointA = (6, 8) # packing a tuple then x1, y1 = pointA # unpacking a tuple print(x1, y1) # 6, 8

  6. x1, y1, x2, y2 = (1, 2, 3, 4) What is the value of x1 and y2?

    1 and 4.

  7. What is the distance between (4, 0) and (0, 0)?

    4 d = (x1 - x2) = 4 - 0 = 4

  8. What is the distance between (4, 3) and (4, 0)?

    3 d = (x1 - x2) + (y1 - y2) = (4 - 4) + (3 - 0) = 0 + 3 = 3

  9. What is the distance between (4, 3) and (0, 0)?

    Using previous formula, we get d = (x1 - x2) + (y1 - y2) = (4 - 0) + (3 - 0) = 4 + 3 = 7 But we know from https://www.mathsisfun.com/algebra/distance-2-points.html

  10. If (x1 - x2) + (y1 - y2) is giving a higher value than what is correct, What can the distance formula be?

    Why not square the x component and square the y component, and then reduce it down by using square root? The distance formula is as follows:

  11. What is the distance between (2, -1) and (5, 3)?

  12. Are you confident of writing the code for Distance between Two Points?

    Test yourself at http://j.mp/twoPointsCC

  13. Write the Python function for calculating the distance between two points.

  14. Write the Python program for calculating the distance between two points.

  15. Tuples are immutable. Explain with an example.

    atuple = (3, 4, 5) atuple[2] = 6 will cause TypeError: 'tuple' object does not support item assignment and that is because tuples are immutable.

  16. We need to change a tuple containing (3, 4, [5, 6, 7]) to (3, 4, [5, 6, 100]). Choice A. Not possible - because tuples are immutable. Choice B. It is possible. What is your choice - A or B?

    Choice B. atuple = (3, 4, [5, 6, 7]) atuple[2][2] = 100 print(atuple) (3, 4, [5, 6, 100]) Tuples are immutable. Tuple elements are mutable.