- dictionaries
Burkay Genç, Ahmet Selman Bozkır, and Selma Dilek
26/04/2023
Problem Fixing
Program testing can be used to show the presence of bugs, but never to show their absence!
Edsger Dijkstra
No amount of experimentation can ever prove me right; a single experiment can prove me wrong.
Albert Einstein
^^^ One sentence summary of the “scientific method”
def is_bigger(x, y): """ Assumes x and y are ints Returns True if y is less than x, else False """
def sqrt(x, eps): """ Assumes x, epsilon floats, x >= 0, epsilon > 0 Returns res such that x-epsilon <= res*res <= x+epsilon """
def sqrt(x, epsilon): """ Assumes x, epsilon floats, x >= 0, epsilon > 0 Returns res such that x-epsilon <= res*res <= x+epsilon """
def isPrime(x): """ Assumes x is a nonnegative int Returns True if x is prime; False otherwise """ if x <= 2: return False for i in range(2, x): if x % i == 0: return False return True
def isPrime(x): """ Assumes x is a nonnegative int Returns True if x is prime; False otherwise """ if x <= 2: return False for i in range(2, x): if x % i == 0: return False return True isPrime(0) # expected value: False
## False
isPrime(2) # expected value: True
## False
def abs(x): """ Assumes x is an int Returns x if x>=0 and –x otherwise """ if x < -1: return -x else: return x
abs(-1)
incorrectly returns -1