test
import requests
def get_gold_price(api_key):
url = f’https://www.metalpriceapi.com/api/latest?access_key={api_key}&base=USD&symbols=XAU’
response = requests.get(url)
data = response.json()
if response.status_code == 200 and “rates” in data:
gold_price = data[“rates”].get(“XAU”, “Price not available”)
print(f”The current price of gold in USD is: ${gold_price}”)
else:
print(“Error fetching the gold price. Check your API key and try again.”)
# Replace ‘your_api_key’ with your actual MetalPriceAPI key
api_key = ‘e239794e65e9ba145547e89ae6d9b8f2’
get_gold_price(api_key)