Added notes to it
Co-authored-by: seaswimmerthefsh@gmail.com <seaswimmerthefsh@gmail.com>
This commit is contained in:
parent
4937c519fa
commit
232cc60d19
3 changed files with 46 additions and 26 deletions
|
@ -6,20 +6,28 @@ RESET = "\033[0m" # Reset to default color
|
|||
|
||||
|
||||
def divide(x: float, y: float) -> float | None:
|
||||
try:
|
||||
x = float(x)
|
||||
y = float(y)
|
||||
try: # This function checks to see if we can convert the input into a float
|
||||
x = float(x) # Tries to convert the x argument into a float
|
||||
y = float(y) # tries to convert the y argument into a float
|
||||
except ValueError:
|
||||
return print(f"{RED}You cannot divide by strings!{RESET}")
|
||||
return print(
|
||||
f"{RED}You cannot divide by strings!{RESET}"
|
||||
) # if the input was unable to be turned into a float, it prints out an error stating that you cannot print out strings
|
||||
|
||||
if y == 0:
|
||||
return print(f"{RED}You cannot divide by 0!{RESET}") # you don't divide by zero
|
||||
if y == 0: # This argument checks to see if the inputted y is a 0
|
||||
return print(
|
||||
f"{RED}You cannot divide by 0!{RESET}"
|
||||
) # If the Y does check out to be a zero, we print out the error that you cannot divide by zero
|
||||
return float(x / y)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
x = input(f"{BLUE}Input a number to divide:{RESET} ")
|
||||
y = input(f"{BLUE}Input a number to divide by:{RESET} ")
|
||||
x = input(
|
||||
f"{BLUE}Input a number to divide:{RESET} "
|
||||
) # Allows us to input a number for X to divide
|
||||
y = input(
|
||||
f"{BLUE}Input a number to divide by:{RESET} "
|
||||
) # Allows us to input a number for Y to divide x by
|
||||
result = divide(x, y)
|
||||
if result is not None:
|
||||
print(f"{GREEN}{result}{RESET}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue