File size: 1,537 Bytes
dd4d7e8
 
6584f8d
 
 
dd4d7e8
6584f8d
 
 
dd4d7e8
6584f8d
 
 
 
 
 
 
 
 
 
dd4d7e8
6584f8d
 
dd4d7e8
6584f8d
 
 
 
 
 
dd4d7e8
6584f8d
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import streamlit as st

# Set up the app's layout
st.set_page_config(page_title="Currency Exchange Calculator", layout="wide")
st.title("🌍💱 Currency Exchange Calculator")

# Sidebar
st.sidebar.title("About the App")
st.sidebar.info("This simple currency converter allows you to exchange between commonly used currencies using predefined exchange rates.")

# Latest hardcoded exchange rates (example rates, replace with the latest you know)
exchange_rates = {
    "USD": 1.0,  # Base currency
    "EUR": 0.91,
    "GBP": 0.78,
    "PKR": 277.5,
    "INR": 83.2,
    "JPY": 141.8,
    "RMB": 7.2,
}

# Main layout with two columns
col1, col2 = st.columns(2)

with col1:
    # User inputs for currency conversion
    st.subheader("Input")
    from_currency = st.selectbox("From Currency", options=exchange_rates.keys(), index=0)
    to_currency = st.selectbox("To Currency", options=exchange_rates.keys(), index=1)
    amount = st.number_input("Amount to Convert", min_value=0.0, value=1.0, step=0.01)

with col2:
    # Perform conversion
    st.subheader("Result")
    if st.button("Convert"):
        try:
            # Conversion logic
            converted_amount = amount * (exchange_rates[to_currency] / exchange_rates[from_currency])
            st.success(f"{amount} {from_currency} = {converted_amount:,.2f} {to_currency}")
        except Exception as e:
            st.error(f"An error occurred: {e}")

# Footer
st.sidebar.markdown("---")
st.sidebar.markdown("**Exchange rates are static and need to be updated manually.**")