hyprland-dotfiles/scripts/growthrate.py

33 lines
1005 B
Python
Raw Permalink Normal View History

2023-02-26 15:09:22 +00:00
# ____ _ _ ____ _
# / ___|_ __ _____ _| |_| |__ | _ \ __ _| |_ ___
# | | _| '__/ _ \ \ /\ / / __| '_ \ | |_) / _` | __/ _ \
# | |_| | | | (_) \ V V /| |_| | | | | _ < (_| | || __/
# \____|_| \___/ \_/\_/ \__|_| |_| |_| \_\__,_|\__\___|
#
# by Stephan Raabe (2023)
# ---------------------------------------------------------------
# DESC: Python script to calculate the growth rate of two numbers
# ---------------------------------------------------------------
import rich
2023-05-11 11:18:52 +00:00
import pyperclip
2023-02-26 15:09:22 +00:00
from rich.console import Console
from rich.prompt import FloatPrompt
2023-05-11 11:18:52 +00:00
# Show prompts
2023-02-26 15:09:22 +00:00
console = Console()
2023-06-19 13:04:00 +00:00
num1 = FloatPrompt.ask("Old value")
2023-05-11 11:18:52 +00:00
num2 = FloatPrompt.ask("New value")
2023-02-26 15:09:22 +00:00
2023-06-19 13:04:00 +00:00
# Calculate the growth rate
2023-02-06 15:11:51 +00:00
gr = ((num2-num1)/num1)
percentage = "{:.2%}".format(gr)
2023-06-19 13:04:00 +00:00
# Print result to the console
2023-02-26 15:09:22 +00:00
console.print(percentage, style="bold")
2023-05-11 11:18:52 +00:00
2023-06-19 13:04:00 +00:00
# Copy result into the system clipboard
2023-05-11 11:18:52 +00:00
pyperclip.copy(percentage)
2023-06-19 13:04:00 +00:00
print("Result has been copied to the clipboard!")