Jump to content
Fórum Script Brasil
  • 0
Sign in to follow this  
MarcosAUG

Python, classes e *args

Question

Crie uma classe que defina um vetor no plano. Crie métodos para permitir obter o versor, módulo e somar ao vetor uma série de outros vetores (usando *args), calcular o produto escalar e produto vetorial

image.png.73ff40f879352c704697eab52a03457a.png

Uma duvida é de como usar a função *args nos métodos que o enunciado pede, e se tenho que mudar os métodos e atributos anteriores?

class Vetor:
    
    def __init__(self, x, y):
        self.__x = x
        self.__y = y
        
    def modulo(self):
        return (self.__x**2 + self.__y**2 )**(1/2)
    
    def versor(self):
        v1 = (self.__x)/(self.__x**2 + self.__y**2 )**(1/2)
        v2 = (self.__y)/(self.__x**2 + self.__y**2 )**(1/2)
        return v1, v2
    
    def soma(self, *args):
        pass
    
 
    
vetorA = Vetor(4,3)
print("Modulo: ", vetorA.modulo())
print("Versor: ", vetorA.versor()) 

 

Edited by MarcosAUG
Complementação

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  



  • Forum Statistics

    • Total Topics
      148434
    • Total Posts
      643870
×
×
  • Create New...