import requests
def fetch_latest_news(api_key):
url = f"https://newsapi.org/v2/top-headlines?country=us&apiKey={api_key}"
response = requests.get(url)
if response.status_code == 200:
articles = response.json().get('articles')
if articles:
print("Latest News Headlines:")
for article in articles:
print(f"- {article['title']}")
else:
print("No articles found.")
else:
print(f"Error fetching news: {response.status_code}")
if __name__ == "__main__":
api_key = input("Enter your NewsAPI key: ")
#sign up at newsapi to get an api key
fetch_latest_news(api_key)