HFUsman commited on
Commit
dd4d7e8
·
verified ·
1 Parent(s): 60d8479

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from forex_python.converter import CurrencyRates, CurrencyCodes
3
+
4
+ # Initialize currency converter
5
+ c = CurrencyRates()
6
+ cc = CurrencyCodes()
7
+
8
+ st.title("Currency Exchange Calculator 🌎💱")
9
+
10
+ # User input: Select currencies
11
+ from_currency = st.selectbox("From Currency", options=list(c.get_rates("").keys()), index=0)
12
+ to_currency = st.selectbox("To Currency", options=list(c.get_rates("").keys()), index=1)
13
+
14
+ # User input: Enter amount
15
+ amount = st.number_input("Enter amount to convert", min_value=0.0, value=1.0, step=0.01)
16
+
17
+ # Calculate exchange rate
18
+ if st.button("Convert"):
19
+ try:
20
+ converted_amount = c.convert(from_currency, to_currency, amount)
21
+ symbol = cc.get_symbol(to_currency)
22
+ st.success(f"{amount} {from_currency} = {symbol}{converted_amount:,.2f} {to_currency}")
23
+ except Exception as e:
24
+ st.error(f"Error: {e}")
25
+
26
+ # Display additional rates
27
+ st.sidebar.title("Additional Features")
28
+ if st.sidebar.checkbox("View Current Rates"):
29
+ rates = c.get_rates(from_currency)
30
+ st.sidebar.write(f"Exchange rates for {from_currency}:")
31
+ st.sidebar.table(rates)