Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,70 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
st.title('Calculateur de monnaie')
|
5 |
|
6 |
# Entrée pour la somme totale à payer
|
7 |
-
total_a_payer = st.number_input('
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
st.
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
st.button('
|
24 |
-
st.
|
25 |
-
|
26 |
-
st.button('
|
27 |
-
st.
|
28 |
-
|
29 |
-
st.button('
|
30 |
-
st.
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
if
|
35 |
-
|
36 |
-
|
37 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
+
# Fonction pour calculer la monnaie à rendre
|
4 |
+
def calculer_monnaie_a_rendre():
|
5 |
+
monnaie_a_rendre = total_paye - total_a_payer
|
6 |
+
return monnaie_a_rendre if monnaie_a_rendre > 0 else 0
|
7 |
+
|
8 |
+
# Initialisation de la session state pour le total payé
|
9 |
+
if 'total_paye' not in st.session_state:
|
10 |
+
st.session_state['total_paye'] = 0.0
|
11 |
+
|
12 |
+
# Interface utilisateur
|
13 |
st.title('Calculateur de monnaie')
|
14 |
|
15 |
# Entrée pour la somme totale à payer
|
16 |
+
total_a_payer = st.number_input('Somme totale à payer', min_value=0.0, value=0.0, format="%.2f", help="Entrez la somme totale à payer.")
|
17 |
+
st.caption("Merci de mettre ´.´ a la place de ','")
|
18 |
+
|
19 |
+
col1, col2, col3 = st.columns(3)
|
20 |
+
with col1:
|
21 |
+
if st.button('0.05€'):
|
22 |
+
st.session_state.total_paye += 0.05
|
23 |
+
with col2:
|
24 |
+
if st.button('0.10€'):
|
25 |
+
st.session_state.total_paye += 0.10
|
26 |
+
with col3:
|
27 |
+
if st.button('0.20€'):
|
28 |
+
st.session_state.total_paye += 0.20
|
29 |
+
|
30 |
+
col1, col2, col3 = st.columns(3)
|
31 |
+
with col1:
|
32 |
+
if st.button('0.50€'):
|
33 |
+
st.session_state.total_paye += 0.50
|
34 |
+
with col2:
|
35 |
+
if st.button('1€'):
|
36 |
+
st.session_state.total_paye += 1.00
|
37 |
+
with col3:
|
38 |
+
if st.button('2€'):
|
39 |
+
st.session_state.total_paye += 2.00
|
40 |
+
|
41 |
+
col1, col2, col3 = st.columns(3)
|
42 |
+
with col1:
|
43 |
+
if st.button('5€'):
|
44 |
+
st.session_state.total_paye += 5.00
|
45 |
+
with col2:
|
46 |
+
if st.button('10€'):
|
47 |
+
st.session_state.total_paye += 10.00
|
48 |
+
with col3:
|
49 |
+
if st.button('20€'):
|
50 |
+
st.session_state.total_paye += 20.00
|
51 |
+
|
52 |
+
col1, col2, col3 = st.columns(3)
|
53 |
+
with col1:
|
54 |
+
if st.button('30€'):
|
55 |
+
st.session_state.total_paye += 30.00
|
56 |
+
with col2:
|
57 |
+
if st.button('40€'):
|
58 |
+
st.session_state.total_paye += 40.00
|
59 |
+
with col3:
|
60 |
+
if st.button(50€'):
|
61 |
+
st.session_state.total_paye += 50.00
|
62 |
+
|
63 |
+
# Afficher le total payé et la monnaie à rendre
|
64 |
+
st.write(f"Total payé: {st.session_state.total_paye:.2f}€")
|
65 |
+
monnaie_a_rendre = calculer_monnaie_a_rendre()
|
66 |
+
st.write(f"Monnaie à rendre: {monnaie_a_rendre:.2f}€")
|
67 |
+
|
68 |
+
# Bouton pour réinitialiser
|
69 |
+
if st.button('Réinitialiser'):
|
70 |
+
st.session_state.total_paye = 0.0
|