473,386 Members | 2,050 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,386 software developers and data experts.

There 's an invalid syntax error but i don't know what's wrong with it.

There 's an invalid syntax error but i don't know what's wrong with it.
the error says

Invalid syntax: print variation_string

Expand|Select|Wrap|Line Numbers
  1.  
  2. import itertools
  3.  
  4. variations = itertools.product('ab', repeat=4)
  5. for variations in variations:
  6.         variation_string = ""
  7.         for letter in variations:
  8.                 variation_string += letter
  9.         print variation_string
  10.  
  11.  
  12.  
Jan 17 '11 #1

✓ answered by dwblas

What version of Python are you using? If it is 3.x, then print is a function:
print(variation_string)
Expand|Select|Wrap|Line Numbers
  1. for variations in variations:
While this is a terrible coding style, it will run as each "variations" points to a different memory address, because for() loop variables are local to the loop (but I wouldn't want to modify or debug it).

3 2322
Mariostg
332 100+
Read your line 5 again. How about
For variation in variations
Then change line 7 accordingly.
Jan 17 '11 #2
dwblas
626 Expert 512MB
What version of Python are you using? If it is 3.x, then print is a function:
print(variation_string)
Expand|Select|Wrap|Line Numbers
  1. for variations in variations:
While this is a terrible coding style, it will run as each "variations" points to a different memory address, because for() loop variables are local to the loop (but I wouldn't want to modify or debug it).
Jan 17 '11 #3
Cut and past the code below and save in a different file; although I see you code in my webbrowser I see that code in the fonts on my system; It's possible the fonts on your system are hiding your syntax error. Although I doubt that.

Your code works fine on my pc. WinXP Pro-32bit SP3, Python 2.7

Expand|Select|Wrap|Line Numbers
  1. import itertools
  2. print('"""')
  3. variations = itertools.product('ab', repeat=4)
  4. for variation in variations:
  5.     # print( variation )
  6.     variation_string = ""
  7.  
  8.     for letter in variation:
  9.         variation_string += letter
  10.         # print(variation_string)
  11.     print(variation_string)
  12. print('"""')
  13.  
  14. """
  15. aaaa
  16. aaab
  17. aaba
  18. aabb
  19. abaa
  20. abab
  21. abba
  22. abbb
  23. baaa
  24. baab
  25. baba
  26. babb
  27. bbaa
  28. bbab
  29. bbba
  30. bbbb
  31. """
Jan 20 '11 #4

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

Similar topics

0
by: DP | last post by:
(2nd post, I think my first may have been to the wrong group - sorry) Hello Perl-ers - I´m hoping I can get some help here, because I'm very lost. Don't know Perl, I'm not a programmer. And...
4
by: Vladimir | last post by:
Can anyone halp me with some questions? Is there multiplatform standart in binary representation of primitive datatypes when you writing it through BinaryWriter? In other words if I write by...
20
by: Sam | last post by:
Hi I'm learning to code with C++ and wrote some very simple code. I think it's consistent with every rule but always got compiling errors that I don't understand. The code include 5 files as...
5
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
1
by: Kenny | last post by:
I have an aspx page (containing a framesets) that appears just fine in the browser (IE6). But there is a little yellow "caution" icon that shows up at the bottom of the browser window with a...
3
by: smorrey | last post by:
Howdy folks, I recently purchased a book on C++ MUD creation and it features alot of nifty tidbits. The book is MUD GAME PROGRAMMING by Ron Penton Publisher: Premier Press Anyways of...
20
by: johnnyboy7 | last post by:
I don't know a lot about ASP and I know even less about SQL. I have been trying to search the web for information to be able to get done what I need. I've tried piecing things together from many...
7
by: Gilles Ganault | last post by:
Hello Data that I download from the web seems to be using different code pages at times, and Python doesn't like this. Google returned a way to handle this, but I'm still getting an error:...
3
by: dragon52 | last post by:
Hi, I installed "mysql-connector-net-5.2.3" and "mysql-gui-tools-5.0-r12-win32". The install seems ok. When I start the "Administrator" or "Query Browser", the login asks for...
1
by: ashlegen | last post by:
Hi guys.I've got a problem.I'm building my php browsergame and i'm stuck into the inventory page.I have a code that seems ok to me but it won't work.Here it is: $inventory = array(); $query =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.