-
Notifications
You must be signed in to change notification settings - Fork 14
updating type hint for solutions #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,14 @@ | |
| # Description: created a function called "fall_distance() that takes an input of seconds and returns | ||
| # the distance an object has fallen." | ||
|
|
||
| time: float = int(input("Please enter an amount of time in second(s): ")) | ||
tnguyen306 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def fall_distance(t): | ||
| '''takes input in seconds and returns distance object has fallen''' | ||
| g = 9.8 # velocity | ||
|
|
||
| return 0.5 * g * t*t | ||
| def fall_distance(t) -> float: | ||
|
||
| """takes input in seconds and returns distance object has fallen""" | ||
| g: float = 9.8 # velocity | ||
|
|
||
| return 0.5 * g * t * t | ||
|
|
||
|
|
||
| print("The distance the object has fallen is : ", fall_distance(time), "meter:") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,21 @@ | ||
| # Author: Brandon Hoffman | ||
| # Date: 10/17/2020 | ||
| # Description: created a function called fib() that calculate a fibonnaci number for a given 'n' without recursion or the golden ratio. | ||
| # Author: Brandon Hoffman Date: 10/17/2020 Description: created a function called fib() that calculate a Fibonacci | ||
| # number for a given 'n' without recursion or the golden ratio. | ||
|
|
||
| def fib(n): | ||
| '''calculate a fibonnaci number given the input 'n' without recursion using the golden ratio''' | ||
|
|
||
| prev_num = 0 | ||
| curr_num = 1 | ||
| sol = 1 | ||
| for i in range(n-1): | ||
| def fib(n) -> int: | ||
|
||
| """calculate a fibonnaci number given the input 'n' without recursion using the golden ratio""" | ||
|
|
||
| prev_num: int = 0 | ||
| curr_num: int = 1 | ||
| sol: int = 1 | ||
| print("The numbers in fibonacci series are : ") | ||
| for i in range(n - 1): | ||
branhoff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sol = curr_num + prev_num | ||
| prev_num = curr_num | ||
| curr_num = sol | ||
|
|
||
|
|
||
| print(sol) | ||
| return sol | ||
|
|
||
|
|
||
| number: int = int(input("Please enter a number to calculate its Fibonacci number: ")) | ||
| print("The Fibonacci number is: ", fib(number)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ class Taxicab: | |
| """ | ||
| Represents a taxicab that tracks the distance traveled when given x and y coordinates | ||
| """ | ||
| def __init__(self, x, y): | ||
| def __init__(self, x, y) -> None: | ||
|
||
| """ | ||
| Creates a taxicab object with x and y coordiantes and intializes an odometer to 0 | ||
| """ | ||
|
|
@@ -16,32 +16,32 @@ def __init__(self, x, y): | |
|
|
||
| self._odometer = 0 | ||
|
|
||
| def get_x_coord(self): | ||
| def get_x_coord(self) -> float: | ||
| """ | ||
| returns the current x coordinate | ||
| """ | ||
| return self._x | ||
|
|
||
| def get_y_coord(self): | ||
| def get_y_coord(self) -> float: | ||
| """ | ||
| returns the current y coordinate | ||
| """ | ||
| return self._y | ||
|
|
||
| def get_odometer(self): | ||
| def get_odometer(self) -> float: | ||
| """ | ||
| sums the abs value of the change in x and y coordinates | ||
| """ | ||
| return self._odometer | ||
|
|
||
| def move_x(self, x_vector): | ||
| def move_x(self, x_vector) -> None: | ||
| """ | ||
| takes in a one-dimensional vector and adds it to the x coordiante as its original value and the odometer as an absolute value | ||
| """ | ||
| self._x += x_vector | ||
| self._odometer += abs(x_vector) | ||
|
|
||
| def move_y(self, y_vector): | ||
| def move_y(self, y_vector) -> None: | ||
| """ | ||
| takes in a one-dimensional vector and adds it to the x coordiante as its original value and the odometer as an absolute value | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from Taxicab import Taxicab | ||
|
|
||
| cab = Taxicab(3, -8) # creates a Taxicab object at coordinates (3, -8) | ||
| cab.move_x(4) # moves cab 4 units "right" | ||
| cab.move_y(-5) # moves cab 5 units "down" | ||
| cab.move_x(-2) # moves cab 2 unit "left" | ||
| print(cab.get_odometer()) # prints the current odometer reading |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,24 @@ | ||
| # Author: Brandon Hoffman | ||
| # Date: 10/25/2020 | ||
| # Description: Sorts a list of numbers and returns the median number in the list | ||
| from array import array | ||
branhoff marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def find_median(some_nums): | ||
|
|
||
| def find_median(some_nums) -> float: | ||
| """ | ||
| Sorts a list of numbers and returns the median value | ||
| """ | ||
| some_nums.sort() | ||
| array_length = len(some_nums) | ||
|
|
||
| mid_index = int(array_length/2) | ||
| mid_index = int(array_length / 2) | ||
|
|
||
| if array_length % 2 == 0: | ||
| mid_index_alt = int((array_length/2)-1) | ||
| mid_index_alt = int((array_length / 2) - 1) | ||
| return (some_nums[mid_index] + some_nums[mid_index_alt]) / 2 | ||
| else: | ||
| return some_nums[mid_index] | ||
|
|
||
|
|
||
|
|
||
| list_of_nums: list[int] = [13, 7, -3, 82, 4] | ||
branhoff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| result = find_median(list_of_nums) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,21 @@ | ||
| # Author: Brandon Hoffman | ||
| # Date: 10/25/2020 | ||
| # Description: create a function that takes a list of names and stores any value that starts with the letter 'K' in a new list concatenated also with the string ' Hoffman' | ||
| # Author: Brandon Hoffman Date: 10/25/2020 Description: create a function that takes a list of names and stores any | ||
| # value that starts with the letter 'K' in a new list concatenated also with the string ' Hoffman' | ||
|
|
||
| def add_surname(name_list): | ||
| def add_surname(name_list) -> list[str]: | ||
| """ | ||
| takes a list of names and stores any value that starts with the letter 'K' in a new list concatenated also with the string ' Hoffman' | ||
| takes a list of names and stores any value that starts with the letter 'K' in a new list concatenated also with | ||
| the string ' Hoffman' | ||
| """ | ||
| return [name + " Hoffman" for name in name_list if name[0] == "K"] | ||
branhoff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| new_name_list: list[str] = [] | ||
| for name in name_list: | ||
| if name[0] == 'K': | ||
| new_name_list += [name + ' Hoffman'] | ||
|
|
||
| return new_name_list | ||
|
|
||
|
|
||
| # testing the function | ||
| names: list[str] = ["Kiki", "Krystal", "Pavel", "MaryKay", "Annie", "Koala"] | ||
| changed_name_lists: list[str] = add_surname(names) | ||
| for name in changed_name_lists: | ||
| print(name) | ||
Uh oh!
There was an error while loading. Please reload this page.