Connecting Tech Pros Worldwide Help | Site Map

variable in python..

Newbie
 
Join Date: Aug 2009
Posts: 4
#1: Aug 26 '09
Hello everyone,

I am new to python and i am stuck with this code.
for a fixed value of kr it was working fine but
i wan to put kr in a for loop.
but each time i get this error

For kr in range(1, 5)
^
SyntaxError: invalid syntax

i put the whole code which uses kr in the for loop of kr
but it doesn't work.


Expand|Select|Wrap|Line Numbers
  1. ...................................................................................................................
  2. # This example computes the diffraction from a superhydrophobic optical grating
  3. # immersed in water. A curved liquid-gas interface spans each groove.
  4.  
  5.  
  6. from mrcwa import *
  7. from tables import *
  8.  
  9. # dimensionless curvature of the interface
  10.  
  11.  
  12. #Variable
  13. M1=0
  14. M2=0
  15. M3=0
  16.  
  17. # groove width
  18. g = 5.0
  19. # wall width
  20. w = 3.0
  21. # depth
  22. h = 6
  23. # period
  24. T = g + w
  25. r = 0.5 * g
  26. #Materials definition
  27. air = material(1.0)
  28. water = material(1.33,'blue')
  29. Si = material((4.367+0.079j),'black')
  30. output_file = open("SuperHydro_varying_kr","w")
  31.  
  32. For kr in range(1, 5)
  33.  
  34.     R=r/kr
  35.     l = R * sqrt( 1 - r**2 / R**2 )
  36.     zeta = R * ( 1 - sqrt( 1 - r**2 / R**2 ) )
  37.  
  38.     if kr < 0:
  39.  
  40.         box + halfspace(-inf, 0.0, Si)
  41.         box + rectangle(g, h, air, (0, -0.5*h) )
  42.         box + circle(R, water, (.0,-l))
  43.  
  44.         ymesh = hstack( ( array([0.0,r]), arange(r+h+zeta-d, h+r+d, d), array([h+g]) ) )
  45.          print 'good'
  46.     elif kr > 0:
  47.  
  48.         box + circle(R, air, (.0,-l))
  49.         box + halfspace(-inf, 0.0, Si)
  50.         box + rectangle(g, h, air, (0, -0.5*h) )
  51.  
  52.         ymesh = hstack( ( array([0.0,r]), arange(r+h-d, h+g+d, d) ) )
  53.  
  54.     xmesh = hstack( (arange(0,g+0.01,0.001), array([T]) ) )
  55.     grating=stack( box.slice(xmesh=xmesh, ymesh=ymesh) )
  56.      print 'bad'
  57.     M1=0
  58.     M2=0
  59.     M3=0
  60.     M =-50
  61.     P = 50
  62.  
  63.     grating.order=(M,P+1)
  64.  
  65.     grating.l = 0.488
  66.  
  67.     grating.fourier()
  68.  
  69.     angles = arange(30,87,1)
  70.     orders = arange(M,P+1)
  71.  
  72.  
  73.     for i,theta in enumerate(angles):
  74.         grating.theta = theta
  75.         grating.wavevec()
  76.         grating.partialr()
  77.         L=grating.partialr()[49]*grating.partialr()[49]
  78.         Q=grating.partialr()[50]*grating.partialr()[50]
  79.         S=grating.partialr()[51]*grating.partialr()[51]
  80.         M1+=L
  81.         M2+=Q
  82.         M3+=S
  83.     output_file.write(" %s  %s  %s  %s \n" % (kr, M1, M2, M3) )
  84. output_file.close()
.................................................. .................................................. ...............
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,560
#2: Aug 26 '09

re: variable in python..


Python keyword for cannot be capitalized! Upper and lower case in Python makes a difference.
Newbie
 
Join Date: Aug 2009
Posts: 4
#3: Aug 26 '09

re: variable in python..


thanx its working now :))
Reply

Tags
need help!!