We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5f4df3b commit ad13a49Copy full SHA for ad13a49
1 file changed
web_programming/crypto_price.py
@@ -11,7 +11,10 @@
11
12
import httpx
13
14
-COINGECKO_URL = "https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"
+COINGECKO_URL = (
15
+ "https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"
16
+)
17
+
18
19
def get_eth_price_usd() -> float:
20
"""Fetch the current ETH price in USD."""
@@ -20,10 +23,12 @@ def get_eth_price_usd() -> float:
23
data = response.json()
21
24
return data["ethereum"]["usd"]
22
25
26
27
def eth_to_usd(eth_amount: float) -> float:
28
"""Convert ETH amount to USD."""
29
return eth_amount * get_eth_price_usd()
30
31
32
if __name__ == "__main__":
33
eth_amount = float(input("Enter ETH amount: "))
34
usd_value = eth_to_usd(eth_amount)
0 commit comments