Wrote more functions in Python for preparation for scatter plot lab.

This commit is contained in:
Louis Cooper 2023-08-02 18:47:29 -04:00
parent c349c533b3
commit fc2336e978
1 changed files with 24 additions and 7 deletions

View File

@ -5,30 +5,47 @@
# None of them are finished; this is your job!
def maximum(data):
"Returns the largest number in data"
raise NotImplementedError
"Returns the biggest number in data"
highest = None
for number in data:
if highest is None:
highest = number
if number > highest:
highest = number
return highest
def minimum(data):
"Returns the smallest number in data"
raise NotImplementedError
lowest = None
for number in data:
if lowest is None:
lowest = number
if number < lowest:
lowest = number
return lowest
def bounds(data):
"Returns a list of the smallest and largest numbers in data"
raise NotImplementedError
return min(data), max(data)
def clamp(value, low, high):
"""Clamps a value to a range from low to high.
Returns value if it is between low and high.
If value is lower than low, returns low. If value is higher than high, returns high.
"""
raise NotImplementedError
if value >= low and value <= high:
return value
elif value > high:
return "High" ,m
else:
return "Low"
def ratio(value, start, end):
"""Returns a number from 0.0 to 1.0, representing how far along value is from start to end.
The return value is clamped to [0, 1], so even if value is lower than start, the return
value will not be lower than 0.0.
"""
raise NotImplementedError
return (value - start) / (end - start)
def scale(value, domain_min, domain_max, range_min, range_max):
"Given a value within a domain, returns the scaled equivalent within range."