Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| # Static exchange rates (approximate) | |
| exchange_rates = { | |
| "USD": 1, | |
| "EUR": 0.9, | |
| "GBP": 0.8, | |
| "JPY": 140, | |
| "PKR": 300 | |
| } | |
| def convert_currency(amount, from_currency, to_currency): | |
| if from_currency == to_currency: | |
| return amount | |
| else: | |
| return amount * (exchange_rates[to_currency] / exchange_rates[from_currency]) | |
| st.title("Currency Converter") | |
| # User input for amount and currencies | |
| with st.container(): | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| amount = st.number_input("Enter amount:", min_value=0.01, step=0.01) | |
| with col2: | |
| from_currency = st.selectbox("From Currency:", options=exchange_rates.keys()) | |
| to_currency = st.selectbox("To Currency:", options=exchange_rates.keys()) | |
| # Button to trigger conversion | |
| if st.button("Convert"): | |
| converted_amount = convert_currency(amount, from_currency, to_currency) | |
| st.success(f"{amount} {from_currency} is equal to {converted_amount:.2f} {to_currency}") | |
| # Add a disclaimer about the limitations of static exchange rates | |
| st.markdown("---") | |
| st.write("**Note:** This converter uses static exchange rates. For accurate and real-time conversions, please use a service that accesses live exchange rates.") |