REMEMBER PYTHON

# MINTE9 2REMEMBER

Last update:   23-07-2021

### INCREMENTAL

p104 ! The goal of incremental development is to avoid long debugging. By Pythagorean Theorem, the distance betwee two points is:
$d = \sqrt{(x2-x1)^2 + (y2-y1)^2}$
p104 The first step will be to define the function, with wrong answer but syntactically correct.
 RunCode
def distance(x1, y1, x2, y2):
return 0.0

d = distance(1, 2, 4, 6)
print(d)   # 0,0
... 4 lines˄˄˄
The next step is to find the differences x2-x1, y2-y1.
 RunCode
def distance(x1, y1, x2, y2):
dx = x2 - x1
dy = y2 - y1
print('dx: ', dx)  # 3
print('dy: ', dy)  # 4
return 0.0

d = distance(1, 2, 4, 6)
print(d)  # 0,0
... 8 lines˄˄˄
Then we compute the sum of squares.
 RunCode
def distance(x1, y1, x2, y2):
dx = x2 - x1
dy = y2 - y1
sum = dx**2 + dy**2
print('sum: ', sum)  # 25
return 0.0

d = distance(1, 2, 4, 6)
print(d)  # 0,0
... 8 lines˄˄˄
Finally, you can use math.sqrt() to compute the result.
 RunCode
import math

def distance(x1, y1, x2, y2):
dx = x2 - x1
dy = y2 - y1
sum = dx**2 + dy**2
return math.sqrt(sum)

d = distance(1, 2, 4, 6)
print(d)  # 5,0
... 8 lines˄˄˄
 CompleteTask
"""
Use incremental development to write a function
The function returns the length of the hypotenuse of a right triangle

The function gets the other two legs as arguments
Record each stage of the development """

# SOLUTION

def hypotenuse(a, b):
???

solution code
 CompleteTask
"""
Write a function called is_palindrom
You can use built-in funciton len to check the string length

A palindorm is a word that is spelled the same backward and forward
Example: noon, redivider

def first(word): return word[0]
def last(word): return word[-1]
def middle(word): return word[1:-1]  """

# SOLUTION

def is_palindrome(word):
???

solution code
Questions
CARD
15
32

A B C D E F
ðŸ””
1/2