Home > front end >  Error: invalid literal for int() with base 10: ''
Error: invalid literal for int() with base 10: ''

Time:01-13

I have written a program to calculate subsidence in the ground after an earthquake. I would like to understand why when I launch the program it tells me as an error: < invalid literal for int() with base 10: '' > at the line "amax = int(ag) * int(ss) * int(st)". Do you know how to solve this problem? Thank you. The code:

import tkinter as tk
from tkinter import Grid, Label, OptionMenu, StringVar, Tk, font, Menu
import tkinter
from tkinter.constants import E, FLAT, W
import math 
                                                                                         
window = tk.Tk()                                                                 
window.geometry("1200x2500")
                                                                                                                     
sedimento_dic = {"Limo":55, "Limo con sabbia":60, "Limo con argilla":65, "Limo 
sabbioso":45, "Limo argilloso":44, "Limo con sabbia argillosa":30, "Limo con sabbia 
debolmente argillosa":70, 
"Limo con argilla sabbiosa":54, "Limo con argilla debolmente sabbiosa":59, 
"Argilla":23, "Argilla con limo":26, "Argilla limosa":51,
"Argilla con sabbia limosa":40, "Argilla con sabbia debolmente limosa":90, "Argilla 
con limo sabbioso":76, "Argilla con limo debolmente sabbioso":11} 

n = None
cedimento = None
risultato_n = None

def calcola_porosità (key):
    n = sedimento_dic.get(key)
risultato_n.configure(text = n)

def calcola_cedimento(spessore, peso_volume, WL, WP, ag, ss, st, vs):
   amax = int(ag) * int(ss) * int(st)
   z = int(spessore) / 2
   peso_volume_eff = int(peso_volume) - 10
   sigma_eff = z * int(peso_volume_eff)
   rd = 1 - (0.015 * z)   

   G_G0 = 0

   if (amax > 0.40):
      G_G0 = 0.28
   else:
       if (amax > 0.30):
          G_G0 = 0.35
       else:
           if (amax > 0.20):
               G_G0 = 0.50
           else:
               if (amax > 0.10):
                   G_G0 = 0.80

  G0 = (int(peso_volume) / 9.81) * pow(vs,2)
  G = int(G_G0) * int(G0)

  gamma_max = 0.65 * (amax / 9.81) * sigma_eff * int(rd) * (1/G)

  if (gamma_max > 0.05):
      ru = 0.2
  else:
      if (gamma_max > 0.10):
          ru = 0.4
      else:
          if (gamma_max > 0.20):
              ru = 0.6
          else:
              if (gamma_max > 0.40):
                ru = 0.8
              else:
                  if (gamma_max > 0.50):
                      ru = 0.95

  e0 = int(n) / (1-int(n))
  IP = int(WL) - int(WP)
  cc = 0.0348   (0.0162 * IP)
  cr = 0.225 * int(cc)
  ev = (int(cr) / (1   int(e0))) * (math.log(1 / (1 - ru),10))  

  cedimento = int(ev) * int(spessore)
  cedimento.configure(text = "Il cedimento è pari a: "   int(ev) * int(spessore))
                                                    
spessore_strato_label = tk.Label(window, text="Spessore dello strato")
spessore_strato_label.grid(row=2, column=0, sticky=W)
finestra_spessore = tk.Entry()                                                                        
finestra_spessore.grid(row=2, column=1, padx=20, sticky=W)

sedimento_label = tk.Label(window, text="Sedimento")
sedimento_label.grid(row=3, column=0, sticky=W)
variable1 = StringVar(window)
variable1.set(" ")
question_menu1 = OptionMenu(window, variable1, *sedimento_dic, 
command=calcola_porosità)
question_menu1.grid(row=3, column=1, sticky=W, padx=20)

risultato_n=tk.Label(window)
risultato_n.grid(row=3, column=1, sticky=E)

peso_volume_label = tk.Label(window, text="Peso di volume")
peso_volume_label.grid(row=4, column=0, sticky=W)
finestra_peso_volume = tk.Entry()                                                                        
finestra_peso_volume.grid(row=4, column=1)

dati_spt_label = tk.Label(window, text="Dati geotecnici", font=("", 16))
dati_spt_label.grid(row=6, column=0, sticky=W,pady=15)

WL_label = tk.Label(window, text="Limite liquido")
WL_label.grid(row=8, column=0, sticky=W)
finestra_WL = tk.Entry()                                                                        
finestra_WL.grid(row=8, column=1) 

WP_label = tk.Label(window, text="Limite plastico")
WP_label.grid(row=9, column=0, sticky=W)
finestra_WP = tk.Entry()                                                                        
finestra_WP.grid(row=9, column=1)                                                

parametri_sismici_label = tk.Label(window, text="Accelerazione sismica di base")
parametri_sismici_label.grid(row=2, column=3, sticky=W, padx=20)
finestra_ag = tk.Entry()                                                                        
finestra_ag.grid(row=2, column=4)

amplificazione_stratigrafica_label = tk.Label(window, text="Amplificazione 
stratigrafica")
amplificazione_stratigrafica_label.grid(row=3, column=3, sticky=W, padx=20)
finestra_ss = tk.Entry()                                                                        
finestra_ss.grid(row=3, column=4)

amplificazione_topografica_label = tk.Label(window, text="Amplificazione 
topografica")
amplificazione_topografica_label.grid(row=4, column=3, sticky=W, padx=20)
finestra_st = tk.Entry()                                                                        
finestra_st.grid(row=4, column=4)


onde_taglio_label = tk.Label(window, text="Velocità delle onde di taglio")
onde_taglio_label.grid(row=5, column=3, sticky=W, padx=20)
finestra_vs = tk.Entry()                                                                        
finestra_vs.grid(row=5, column=4)   

first_button =  tk.Button(text = "Calcola cedimento atteso", command = lambda: 
calcola_cedimento(finestra_spessore.get(),
finestra_peso_volume.get(), finestra_WL.get(), finestra_WP.get(), finestra_ag.get(), 
finestra_ss.get(), finestra_st.get(), finestra_vs.get()))                                                                        
first_button.grid(row=11, column=0) 

cedimento = tk.Label(window)
cedimento.grid(row=12, column=0, sticky=W)

if __name__ == "__main__":
    window.mainloop()

CodePudding user response:

5th or 6th or 7th argument passed to calcola_cedimento is empty string, i.e. at least one of following returned empty string

finestra_ag.get()
finestra_ss.get()
finestra_st.get()

If user is allowed to let said entries empty you should provide default values for this case. If for example ag value should be "1" in such case, you might do

ag = "1" if ag=="" else ag

before

amax = int(ag) * int(ss) * int(st)
  •  Tags:  
  • Related