Home Foros Foro dudas Foro Python Se puede entrar en una función un vector en forma de tupla de dos componentes

Se puede entrar en una función un vector en forma de tupla de dos componentes

Viendo 3 entradas - de la 1 a la 3 (de un total de 3)
  • Autor
    Entradas
  • #17963

    Antonio Alvarez
    Participante

    se puede entrar en una función un vector en forma de tupla de dos componentes

    te envío este ejemplo sencillo

    en vez de ( px,py,v1,v2 )    (p,v) siendo p una tupla con dos componentes y v también

    lo he intentado y no funciona
    <div style=»color: #ffffff; background-color: #193549; font-family: Consolas, ‘Courier New’, monospace; font-size: 20px; line-height: 27px; white-space: pre;»>
    <div><span style=»color: #0088ff; font-style: italic;»>#recta que pasa por un pto y tiene un vector director</span></div>
    <div><span style=»color: #ff9d00;»>def</span><span style=»color: #9effff;»> </span><span style=»color: #ffc600;»>rectpv</span><span style=»color: #9effff;»> </span><span style=»color: #ffee80;»>(</span><span style=»color: #e1efff;»>px</span><span style=»color: #e1efff;»>,</span><span style=»color: #e1efff;»>py</span><span style=»color: #e1efff;»>,</span><span style=»color: #e1efff;»>v1</span><span style=»color: #e1efff;»>,</span><span style=»color: #e1efff;»>v2</span><span style=»color: #ffee80;»>)</span><span style=»color: #e1efff;»>:</span></div>
    <div>    m<span style=»color: #ff9d00;»>=</span><span style=»color: #e1efff;»>v2</span><span style=»color: #ff9d00;»>/</span><span style=»color: #e1efff;»>v1</span></div>
    <div>    n<span style=»color: #ff9d00;»>=-</span><span style=»color: #e1efff;»>((</span><span style=»color: #e1efff;»>px</span><span style=»color: #ff9d00;»>*</span><span style=»color: #e1efff;»>v2</span><span style=»color: #ff9d00;»>/</span><span style=»color: #e1efff;»>v1</span><span style=»color: #e1efff;»>)</span><span style=»color: #ff9d00;»>-</span><span style=»color: #e1efff;»>py</span><span style=»color: #e1efff;»>)</span></div>
    <div>    <span style=»color: #ff9d00;»>return</span> m<span style=»color: #e1efff;»>,</span>n</div>
    <div>xp<span style=»color: #ff9d00;»>=</span><span style=»color: #ffc600;»>float</span><span style=»color: #e1efff;»>(</span><span style=»color: #ffc600;»>input</span><span style=»color: #9effff;»> </span><span style=»color: #e1efff;»>(</span><span style=»color: #92fc79;»>»</span><span style=»color: #a5ff90;»>coordenada x del pto:  </span><span style=»color: #92fc79;»>»</span><span style=»color: #e1efff;»>))</span></div>
    <div>yp<span style=»color: #ff9d00;»>=</span><span style=»color: #ffc600;»>float</span><span style=»color: #e1efff;»>(</span><span style=»color: #ffc600;»>input</span><span style=»color: #9effff;»> </span><span style=»color: #e1efff;»>(</span><span style=»color: #92fc79;»>»</span><span style=»color: #a5ff90;»>coordenada y del pto:  </span><span style=»color: #92fc79;»>»</span><span style=»color: #e1efff;»>))</span></div>
    <div>V1<span style=»color: #ff9d00;»>=</span><span style=»color: #ffc600;»>float</span><span style=»color: #e1efff;»>(</span><span style=»color: #ffc600;»>input</span><span style=»color: #9effff;»> </span><span style=»color: #e1efff;»>(</span><span style=»color: #92fc79;»>»</span><span style=»color: #a5ff90;»>primera comp del vector:  </span><span style=»color: #92fc79;»>»</span><span style=»color: #e1efff;»>))</span></div>
    <div>V2<span style=»color: #ff9d00;»>=</span><span style=»color: #ffc600;»>float</span><span style=»color: #e1efff;»>(</span><span style=»color: #ffc600;»>input</span><span style=»color: #9effff;»> </span><span style=»color: #e1efff;»>(</span><span style=»color: #92fc79;»>»</span><span style=»color: #a5ff90;»>segunda comp del vector:  </span><span style=»color: #92fc79;»>»</span><span style=»color: #e1efff;»>))</span></div>
    <div>recta <span style=»color: #ff9d00;»>=</span> <span style=»color: #ffc600;»>rectpv</span><span style=»color: #e1efff;»>(</span>xp<span style=»color: #e1efff;»>,</span>yp<span style=»color: #e1efff;»>,</span>V1<span style=»color: #e1efff;»>,</span>V2<span style=»color: #e1efff;»>)</span></div>
    <div><span style=»color: #ffc600;»>print</span><span style=»color: #9effff;»> </span><span style=»color: #e1efff;»>(</span><span style=»color: #92fc79;»>»</span><span style=»color: #a5ff90;»>m  ,  n</span><span style=»color: #92fc79;»>»</span><span style=»color: #e1efff;»>)</span></div>
    <div><span style=»color: #ffc600;»>print</span><span style=»color: #9effff;»> </span><span style=»color: #e1efff;»>(</span>recta<span style=»color: #e1efff;»>)</span></div>
    </div>

    #17964

    Antonio Alvarez
    Participante

    lo siento se ha copiado mal el código

    el código es este
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%; font-family: Consolas; mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New Roman’; mso-fareast-language: ES;»>#recta que pasa por un pto y tiene un vector director</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%; font-family: Consolas; mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New Roman’; mso-fareast-language: ES;»>def rectpv (px,py,v1,v2):</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%; font-family: Consolas; mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New Roman’; mso-fareast-language: ES;»>    m=v2/v1</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%; font-family: Consolas; mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New Roman’; mso-fareast-language: ES;»>    n=-((px*v2/v1)-py)</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%; font-family: Consolas; mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New Roman’; mso-fareast-language: ES;»>    return m,n</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%; font-family: Consolas; mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New Roman’; mso-fareast-language: ES;»>xp=float(input («coordenada x del pto:  «))</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%; font-family: Consolas; mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New Roman’; mso-fareast-language: ES;»>yp=float(input («coordenada y del pto:  «))</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%; font-family: Consolas; mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New Roman’; mso-fareast-language: ES;»>V1=float(input («primera comp del vector:  «))</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%; font-family: Consolas; mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New Roman’; mso-fareast-language: ES;»>V2=float(input («segunda comp del vector:  «))</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%; font-family: Consolas; mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New Roman’; mso-fareast-language: ES;»> </span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%; font-family: Consolas; mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New Roman’; mso-fareast-language: ES;»>recta = rectpv(xp,yp,V1,V2)</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%; font-family: Consolas; mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New Roman’; mso-fareast-language: ES;»>print («m  ,  n»)</span></p>
    <span style=»font-size: 14.0pt; line-height: 115%; font-family: Consolas; mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New Roman’; mso-ansi-language: ES; mso-fareast-language: ES; mso-bidi-language: AR-SA;»>print (recta)</span>
    <p class=»MsoNormal»></p>

    #17965

    Antonio Alvarez
    Participante

    perdón ha vuelto a salir mal
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%;»>#recta que pasa por un pto y tiene un vector director</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%;»>def rectpv (px,py,v1,v2):</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%;»><span style=»mso-spacerun: yes;»>    </span>m=v2/v1</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%;»><span style=»mso-spacerun: yes;»>    </span>n=-((px*v2/v1)-py)</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%;»><span style=»mso-spacerun: yes;»>    </span>return m,n</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%;»>xp=float(input («coordenada x del pto:<span style=»mso-spacerun: yes;»>  </span>»))</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%;»>yp=float(input («coordenada y del pto:<span style=»mso-spacerun: yes;»>  </span>»))</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%;»>V1=float(input («primera comp del vector:<span style=»mso-spacerun: yes;»>  </span>»))</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%;»>V2=float(input («segunda comp del vector:<span style=»mso-spacerun: yes;»>  </span>»))</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%;»> </span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%;»>recta = rectpv(xp,yp,V1,V2)</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%;»>print («m<span style=»mso-spacerun: yes;»>  </span>,<span style=»mso-spacerun: yes;»>  </span>n»)</span></p>
    <p class=»MsoNormal»><span style=»font-size: 14.0pt; line-height: 115%;»>print (recta)</span></p>

Viendo 3 entradas - de la 1 a la 3 (de un total de 3)
  • Debes estar registrado para responder a este debate.