473,320 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

variable in python..

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()
.................................................. .................................................. ...............
Aug 26 '09 #1
2 1697
bvdet
2,851 Expert Mod 2GB
Python keyword for cannot be capitalized! Upper and lower case in Python makes a difference.
Aug 26 '09 #2
thanx its working now :))
Aug 26 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Brian Jones | last post by:
I'm sure the solution may be obvious, but this problem is driving me mad. The following is my code: class a(object): mastervar = def __init__(self): print 'called a'
83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
6
by: Hansan | last post by:
Hi all. I am working on a webpage where I use python and html. When I want to send one variable to a new script/page I use the following code: 0) print '''<input type=hidden name="eventid"...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
78
by: Josiah Manson | last post by:
I found that I was repeating the same couple of lines over and over in a function and decided to split those lines into a nested function after copying one too many minor changes all over. The only...
2
by: neeebs | last post by:
Hi, I'm not sure if this is a javascript problem per se, but here goes. I have an xsl document with a python function defined within a <script> block. Elsewhere in the xsl file, within a python...
4
by: Stephen Cattaneo | last post by:
Hello all, I am attempting to execute an automated test (written in Python) via cron. I have to check the HOSTNAME variable as part of the test, oddly under cron the HOSTNAME environment...
0
by: Cameron Simpson | last post by:
On 17Aug2008 21:25, John Nagle <nagle@animats.comwrote: Because $HOSTNAME is a bash specific variable, set by bash but NOT EXPORTED! Like $0 and a bunch of other "private" variables, subprocesses...
0
by: Timothy Grant | last post by:
On Fri, Aug 29, 2008 at 12:48 AM, Alexis Boutillier <alexis.boutillier@arteris.comwrote: http://docs.python.org/ref/import.html -- Stand Fast, tjg.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.