Ver Mensaje Individual
  #13 (permalink)  
Antiguo 15/10/2010, 21:34
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Menú con while.

La identacion de tu programa:
Código Python:
Ver original
  1. from math import acos, pi, sqrt
  2.  
  3. opcion = ''
  4. while opcion in "abcdefghi":
  5.     print '''Selecciona una opcion:
  6.            a) Introducir el primer vector.
  7.            b) Introducir el segundo vector.
  8.            c) Calcular la suma.
  9.            d) Calcular la diferencia.
  10.            e) Calcular el producto escalar.
  11.            f) Calcular el producto vectorial.
  12.            g) Calcular el angulo (en gastos) entre ellos.
  13.            h) Calcular la longitud.
  14.            i) Finalizar. '''
  15.  
  16.     opcion = raw_input('Pulsa a, b, c, d, e, f, g, h o i, luego pulsa retorno de carro: ')
  17.  
  18.     # Primer vector.
  19.     if  opcion == 'a':
  20.         x1 = float(raw_input('Introduce valor x1: '))
  21.         y1 = float(raw_input('Introduce valor y1: '))
  22.         z1 = float(raw_input('Introduce valor z1: '))
  23.      
  24.     # Segundo vector.
  25.     elif opcion == 'b':
  26.         x2 = float(raw_input('Introduce valor x2: '))
  27.         y2 = float(raw_input('Introduce valor y2: '))
  28.         z2 = float(raw_input('Introduce valor z2: '))
  29.     # Suma.
  30.     elif opcion == 'c':
  31.      
  32.             suma = (x1 + x2, y1 + y2, z1 + z2)
  33.             print suma
  34.      
  35.     # Diferencia.
  36.     elif opcion == 'd':
  37.      
  38.             diferencia = (x1 - x2, y1 - y2, z1 - z2)
  39.             print diferencia
  40.      
  41.     # Producto escalar.
  42.     elif opcion == 'e':
  43.      
  44.             producto = (x1 * x2 + y1 * y2 + z1 * z2)
  45.             print producto
  46.      
  47.      # Producto vectorial.
  48.     elif opcion == 'f':
  49.      
  50.             vectorial = (y1 * z2 - z1 * y2, z1 * x2 - x1 * z2, x1 * y2 - y1 * x2)
  51.             print vectorial
  52.      
  53.     # Angulo.
  54.     elif opcion == 'g':
  55.             print  (180 / pi) * arcos * (x1 * x2 + y1 * y2 + z1 * z2) / (sqrt(x1**2 + y1**2 + z1**2) * sqrt(x2**2 + y2**2 + z2**2))
  56.      
  57.     # Longitud.
  58.     elif opcion == 'h':
  59.      
  60.             x = float(raw_input('Introduce valor x: '))
  61.             y = float(raw_input('Introduce valor y: '))
  62.             z = float(raw_input('Introduce valor z: '))
  63.      
  64.             longitud = sqrt(x**2+y**2+z**2)
  65.             print longitud
  66.      
  67.     elif opcion == 'i':
  68.             print 'Solo hay sietes opciones: a, b, c, d, e, f o g. Usted has tecleado', opcion
  69.     print 'Gracias por usar el programa.'