Exercises for accounting in html with Python script

This script makes you do accounting exercises in html with Python to help you manage the html code easily. Running the script you will have the html text in the console to be saved in an html file that will run the code to make the exercise. In the video there is the explanation of how the code works so that you can change the exercise as you want.

This is the colaboratory notebook with the code you see in the video.

https://colab.research.google.com/drive/1Wz1vRgV6Cs0ayeZBgFQpNiEBjLh-nwgj?usp=sharing

'''
crea esercizi in partita doppia come questo:

https://aziendaitalia.altervista.org/esercizio-in-partita-doppia-sulle-vendite/


'''




def conto(titolo, dare="0", avere="0"):
  global testo, sol, darecount, averecount

  # Creazione del conto in html
  testo += f"""<!-- {titolo} -->
  <table border=1 style="width:300">
  <td colspan=2><center>{titolo}</center><tr>
  <td  style="width:150">
<input type="text" id="dare{darecount}" style="width:150" value=0></td><td style="width:150">
<input type="text" id="avere{averecount}" style="width:150" value=0></td>
  </table><br><br> <!-- Fine conto {titolo}-->
"""
  sol += f"{dare} {avere} | "
  obj_input_name.append([f"dare{darecount}.value", f"avere{averecount}.value"])
  darecount +=1
  averecount +=1
  return testo


def pulsante_di_verifica():
  global testo, sol, stringa

  sol = sol[:-1]
  stringa = ""
  for d,a in obj_input_name:
    stringa += f"{d} + ' ' + {a} + ' | ' + "
  stringa = stringa[:-6]
  stringa = stringa + "|'"
  # stringa += "'|'"
  testo += f"""<button onclick="if ({stringa}=='{sol}'){{ver1.value='giusto'}}else{{ver1.value='sbagliato'}};inp1.value={stringa}+' '+ver1.value; console.log({stringa});console.log('{sol}');">Verifica risposte</button><input id='ver1' type='text'>"""
  return stringa


def tag(_t, testo):
  return f"<{_t}>{testo}</{_t}>"




stringa = ""
darecount = 1
averecount = 1
testo = ""
sol = ""
obj_input_name = []


# ==================== | ESERCIZIO 1 | ====================================== #
# solo per la prima traccia lascia testo = tag...
traccia = "Emessa fattura per 250 € + 10% di IVA"
testo = tag("h3", "Esercizio") + tag("p",traccia) + testo
# ogni volta che crei un conto si aggiunge la stringa col codice a testo
conto("Crediti v/clienti", "275", "0")
conto("Iva a debito", "0", "25")
conto("Merci c/vendite", "0", "250")

# alla fine salva un file col testo
# pulsante_di_verifica()

escount = 2
def dopotesto1(testodopo1):
  ''' chiama prima dei conti per inserire la traccia dal 2ndo esercizio in poi '''
  global testo, escount

  traccia2 = testodopo1
  traccia2 = tag("p", traccia2)
  traccia2 = tag("h3", f"Esercizio {escount}") + traccia2
  escount += 1
  testo = testo + tag("p", traccia2)
  return testo


# ============= ESERCIZIO 2 ================== tutti i prossimi esercizi così
testo = dopotesto1("Ricevuto pagamento in contanti per fattura di vendita precedente")
conto("Denaro in cassa", "275", "0")
conto("Crediti v/clienti", "0", "275")
# ================ fine esercizio 2 ==========

pulsante_di_verifica()
print(testo)

# print("


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

")

Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Refinishing

Some better coding, maybe

'''
crea esercizi in partita doppia come questo:

https://aziendaitalia.altervista.org/esercizio-in-partita-doppia-sulle-vendite/


'''




def conto(traccia="", titolo="", dare="0", avere="0"):
  ''' creates a text with a table with the account name and the 2 sections Dare Avere '''
  global testo, sol, darecount, averecount

  # Creazione del conto in html
  testo += f"""

  <!-- #############  {titolo}  ################  -->
  <!-- #############  {traccia}  ################  -->


  <table border=1 style="width:300">
  <td colspan=2><center>{titolo}</center><tr>
  <td  style="width:150">

  <!-- ####  D A R E   ######## -->
<input type="text" id="dare{darecount}" style="width:150" value=0></td><td style="width:150">


<!-- #####  A V E R E  ###### -->

<input type="text" id="avere{averecount}" style="width:150" value=0></td>
  </table><br><br> <!-- Fine conto {titolo}-->
"""
  sol += f"{dare} {avere} | "
  obj_input_name.append([f"dare{darecount}.value", f"avere{averecount}.value"])
  darecount +=1
  averecount +=1
  return testo


def pulsante_di_verifica():
  ''' call this at the end of the conti(...) to see if the user inputs are right '''
  global testo, sol, stringa

  sol = sol[:-1]
  stringa = ""
  for d,a in obj_input_name:
    stringa += f"{d} + ' ' + {a} + ' | ' + "
  stringa = stringa[:-6]
  stringa = stringa + "|'"
  # stringa += "'|'"
  testo += f"""

<!-- ############### VERIFY INPUT ################ -->

  <button onclick="if ({stringa}=='{sol}'){{ver1.value='giusto'}}else{{ver1.value='sbagliato'}};inp1.value={stringa}+' '+ver1.value; console.log({stringa});console.log('{sol}');">Verifica risposte</button><input id='ver1' type='text'>"""
  return stringa


def tag(_t, testo):
  ''' Easy create html tags

  Example

  tag('p', 'hello')

  output

  <p>hello</p>
  '''
  return f"<{_t}>{testo}</{_t}>"




stringa = ""
darecount = 1
averecount = 1
testo = ""
sol = ""
obj_input_name = []


def conti(traccia, pd):
  ''' this calls the conti function to create the table for the accounts '''
  for cnt in pd:
    conto(traccia, cnt[0],cnt[1],cnt[2])


escount = 1
def traccia(testo_traccia):
  ''' prints the text to make the exercise, call this before conti(...) '''
  global testo, escount

  tracc = tag("p", testo_traccia)
  tracc = tag("h3", f"Esercizio {escount}") + tracc
  escount += 1
  testo = testo + tag("p", tracc)
  

''' Example
# for each exercise_
# first call traccia and then conti
# traccia will create html for text
# conti will show the tables with accounts

# when you finished with exercises call pulsante_di_verifica()

# ==================== | ESERCIZIO 1 | ====================================== #
traccia1 = traccia("Emessa fattura per 250 € + 10% di IVA")
# Put the right amount in the right side
conti(traccia1,(
  ("Crediti v/clienti", "275", "0"),
  ("Iva a debito", "0", "25"),
  ("Merci c/vendite", "0", "250")))


'''



# ==================== | ESERCIZIO 1 | ====================================== #
traccia1 = traccia("Emessa fattura per 250 € + 10% di IVA")
# ogni volta che crei un conto si aggiunge la stringa col codice a testo
conti(traccia1,(
  ("Crediti v/clienti", "275", "0"),
  ("Iva a debito", "0", "25"),
  ("Merci c/vendite", "0", "250")))


# ============= ESERCIZIO 2 ================== tutti i prossimi esercizi così
traccia2 = traccia("Ricevuto pagamento in contanti per fattura di vendita precedente")
conti(traccia2,(
  ("Denaro in cassa", "275", "0"),
  ("Crediti v/clienti", "0", "275")))


# Pulsante finale di verifica
pulsante_di_verifica()

# Copia questo testo in un file html
print(testo)

# This is for the blog
# print("


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

")

Even better

'''
crea esercizi in partita doppia come questo:

https://aziendaitalia.altervista.org/esercizio-in-partita-doppia-sulle-vendite/


'''




def esercizio(text, dati):
  ''' creates a text with a table with the account name and the 2 sections Dare Avere '''
  global testo, sol, darecount, averecount

  # Creazione del conto in html
  traccia(text)
  for conto in dati:
    titolo, dare, avere = conto
    testo += f"""

    <!-- {titolo}   {text}  Dare: {dare} Avere: {avere} -->

    <table border=1 style="width:300">
    <td colspan=2><center>{titolo}</center><tr>
    <td  style="width:150">
  <input type="text" id="dare{darecount}" style="width:150" value=0></td><td style="width:150">
  <input type="text" id="avere{averecount}" style="width:150" value=0></td>
    </table><br><br>



  """
    sol += f"{dare} {avere} | "
    obj_input_name.append([f"dare{darecount}.value", f"avere{averecount}.value"])
    darecount +=1
    averecount +=1
  


def pulsante_di_verifica():
  ''' call this at the end of the conti(...) to see if the user inputs are right '''
  global testo, sol, stringa

  sol = sol[:-1]
  stringa = ""
  for d,a in obj_input_name:
    stringa += f"{d} + ' ' + {a} + ' | ' + "
  stringa = stringa[:-6]
  stringa = stringa + "|'"
  # stringa += "'|'"
  testo += f"""

<!-- ############### VERIFY INPUT ################ -->

  <button onclick="if ({stringa}=='{sol}'){{ver1.value='giusto'}}else{{ver1.value='sbagliato'}};inp1.value={stringa}+' '+ver1.value; console.log({stringa});console.log('{sol}');">Verifica risposte</button><input id='ver1' type='text'>"""
  return stringa


def tag(_t, testo):
  ''' Easy create html tags

  Example

  tag('p', 'hello')

  output

  <p>hello</p>
  '''
  return f"<{_t}>{testo}</{_t}>"


stringa = ""
darecount = 1
averecount = 1
testo = ""
sol = ""
obj_input_name = []


escount = 1
def traccia(testo_traccia):
  ''' prints the text to make the exercise, call this before conti(...) '''
  global testo, escount
  testo_puro = testo
  tracc = tag("p", testo_traccia)
  tracc = tag("h3", f"Esercizio {escount}") + tracc
  escount += 1
  testo = testo + tag("p", tracc)
  
  

# ==================== | ESERCIZIO 1 | ====================================== #
esercizio("Emessa fattura per 250 € + 10% di IVA",(
  ("Crediti v/clienti", "275", "0"),
  ("Iva a debito", "0", "25"),
  ("Merci c/vendite", "0", "250")))


# ============= ESERCIZIO 2 ================== tutti i prossimi esercizi così
esercizio("Ricevuto pagamento in contanti per fattura di vendita precedente",(
  ("Denaro in cassa", "275", "0"),
  ("Crediti v/clienti", "0", "275")))


# Pulsante finale di verifica
pulsante_di_verifica()

# Copia questo testo in un file html
print(testo)

# This is for the blog
# print("


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

")

Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.