can’t Multiply Sequence by non-int of type 'float'

Asked

Viewed 12,643 times

5

Error: can’t Multiply Sequence by non-int of type 'float'

I am facing this error, I know it involves variable types, but I do not know how to make the entry receive a float type value

#TRANSOFORMAÇÃO DE COORDENADAS GEODÉSICAS EM COORDENADAS PLANAS – SISTEMA UTM

from tkinter import *
import math
class SAD69:
    def __init__(self,master):


        frame = Frame(master)
        frame.grid(row=0)
        self.A = 1.0050526248
        self.B = 0.0050632321
        self.C = 10.628107*pow(10,-6)
        self.D = 20.821897*pow(10,-9)
        self.E = 3.9327535*pow(10,-11)
        self.F = 6.5553406*pow(10,-14)
        self.alpha = 111133.3486
        self.delta = 0.021986053
        self.beta =  16.03895511
        self.eps = 3.114475*pow(10,-5)
        self.gama = 16.83348972
        self.x = 4.1531106*pow(10,-8)
        self.pi = 3.141592654
        self.a = 6378160
        self.k = 0.9996
        self.p0 = 57.2957795131
        self.e=0.0066945419
        self.n = 6382845.536
        self. l = 0.0067396609
        self.entry1=Entry(frame)
        self.entry1.grid(row = 4, column =1)
        self.label2 = Label(frame,text='Digite a latitude do ponto >>').grid(row=4,column=0)
        self.entry2=Entry(frame,text='LONGITUDE do ponto')
        self.entry2.grid(row=4, column =3)
        self.label3 =Label(frame,text='Digite a longitude do ponto >>').grid(row=4,column=2)
        self.bt1 =Button(frame,text='Converter',fg='blue',command=self.GEOPLAN)
        self.bt1.grid(row=3, column=1)
    def GEOPLAN(self):
        fia =(self.entry1.get())
        la = (self.entry2.get())
        S = self.a*((1-self.e)*((self.A*(fia*self.pi)/180)-(0.5*self.B*math.sin(2*fia*0.017453292))+(0.25*self.C*math.sin(4*fia*0.017453292))-((1/6)*self.D*math.sin(6*fia*0.017453292))+((1/8)*self.E*math.sin(8*fia*0.017453292))-(0.1*self.F*math.sin(10*fia*0.017453292))))
        I = self.k*self.S
        dl = 3600*(51-la)
        p = dl*0.0001




root = Tk()
root.title='TRANSOFORMAÇÃO DE COORDENADAS GEODÉSICAS EM COORDENADAS PLANAS – SISTEMA UTM'

x=SAD69(root)
root.mainloop()
  • o Error occurs in GEOPLAN function

1 answer

4


This error means that a variable containing a sequence (list, tuple, string, etc.) is being multiplied by a float. In Python, if you multiply a sequence by an integer number, it repeats that sequence several times:

>>> [1,2,3] * 4
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]
>>> (10,20) * 3
(10, 20, 10, 20, 10, 20)
>>> "teste" * 5
'testetestetestetesteteste'

But if you try to multiply by a float, this error occurs:

>>> [1,2,3] * 1.5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'float'

In his job GEOPLAN the variables fia and la are the result of the Entry.get, which returns the text of a control. The error then occurs because you are trying to multiply this text by a float, without first converting it to a number.

Try converting these two variables into floats before using them:

fia = float(self.entry1.get())
la = float(self.entry2.get())

It can also be interesting to check its format before the conversion, in case the user has entered something that is not a number (I have no experience with Tkinter, so I don’t know whether or not he can do this validation/conversion automatically).

  • I tried that, but he points out that it was not possible to convert:/.

  • Actually partner, I downloaded the last version of python and it really converted the way you said.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.