728x90
반응형
✔ GPT 입력
: 파이썬으로 환율 변환기를 만들어줘 가입이 필요 없는 방식으로
pip install requests

✔ GPT 가 작성한 코드
import requests
def get_exchange_rate(base_currency, target_currency):
url = f"https://api.exchangerate-api.com/v4/latest/{base_currency}"
response = requests.get(url)
data = response.json()
return data["rates"].get(target_currency)
def currency_converter(amount, base_currency, target_currency):
exchange_rate = get_exchange_rate(base_currency, target_currency)
if not exchange_rate:
return None
return amount * exchange_rate
if __name__ == "__main__":
print("Currency Converter")
print("===================")
base_currency = input("Enter the base currency (e.g., USD, EUR, GBP): ").upper()
target_currency = input("Enter the target currency (e.g., USD, EUR, GBP): ").upper()
amount = float(input("Enter the amount to convert: "))
converted_amount = currency_converter(amount, base_currency, target_currency)
if converted_amount is not None:
print(
f"{amount} {base_currency} is equivalent to {converted_amount:.2f} {target_currency}."
)
else:
print("Currency conversion failed. Please check the currencies you entered.")
✔ 결과

반응형
'Chatgpt' 카테고리의 다른 글
Gpt로 프로그램 코드짜기 단어장만들기 파이썬 (0) | 2023.08.07 |
---|---|
Chatgpt 이용한 프로그램 짜기 - 파이썬 영어 문서 한글 번역 (0) | 2023.07.29 |
Chatgpt 이용한 프로그램 짜기 5 - 파이썬(CPU, RAM, 네트워크 사용량) (0) | 2023.07.19 |
Chatgpt 이용한 프로그램 짜기 4 - 파이썬(QR코드 생성) (0) | 2023.07.18 |
Chatgpt 이용한 프로그램 짜기 3 - 파이썬(텍스트 음성변환) (0) | 2023.07.17 |