473,794 Members | 2,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

an error in commented code?

Here's my code, with the error following it:

props = ['A', 'B', 'C', 'D']
group1 = ['C', 'A', 'D', 'B', 17]
group2 = ['A', 'B', 'D', 'C', 32]
group3 = ['D', 'B', 'C', 'A', 34]
group4 = ['B', 'A', 'C', 'D', 17]

# Submitter: Michael Davies
def all_perms(str):
if len(str) <=1:
yield str
else:
for perm in all_perms(str[1:]):
for i in range(len(perm) +1):
#nb str[0:1] works in both string and list contexts
yield perm[:i] + str[0:1] + perm[i:]

def checkOrder(x, y):
x_votes = 0
y_votes = 0

if group1.index(x) < group1.index(y) :
x_votes += group1[4]
else:
y_votes += group1[4]

if group2.index(x) < group2.index(y) :
x_votes += group2[4]
else:
y_votes += group2[4]

if group3.index(x) < group3.index(y) :
x_votes += group3[4]
else:
y_votes += group3[4]

if group4.index(x) < group4.index(y) :
x_votes += group4[4]
else:
y_votes += group4[4]

if x_votes > y_votes:
return x
else:
return y

for order in all_perms(props ):
# if reduce(checkOrd er, order) == 'A':
# print 'A wins:'
# print order
# if reduce(checkOrd er, order) == 'B':
# print 'B wins:'
# print order
if reduce(checkOrd er, order) == 'C':
print 'C wins:'
print order
# if reduce(checkOrd er, order) == 'D':
# print 'D wins:'
# print order

*** Error in script or command!

Traceback (most recent call last):
File "C:\Python24\my scripts\ecco\1-1-1.py", line 60
# print order
^
SyntaxError: invalid syntax


Line 60 also happens to be the very last line, which is commented. I've
tried a couple of different things to see if it's a whitespace problem,
but it doesn't seem to be. I'm just confused why it detects an error in
the commented code anyway.

Thanks.
Apr 28 '06 #1
4 1254
Tried adding a "\n" (i.e. press the enter key) after the last line
(i.e. right after the word "order") so that you don't end with a
comment.

André

Apr 28 '06 #2
André wrote:
Tried adding a "\n" (i.e. press the enter key) after the last line
(i.e. right after the word "order") so that you don't end with a
comment.

André


Weird, but it worked! :)
Apr 28 '06 #3
John Salerno wrote:
Here's my code, with the error following it:

props = ['A', 'B', 'C', 'D']
group1 = ['C', 'A', 'D', 'B', 17]
group2 = ['A', 'B', 'D', 'C', 32]
group3 = ['D', 'B', 'C', 'A', 34]
group4 = ['B', 'A', 'C', 'D', 17]

# Submitter: Michael Davies
def all_perms(str):
if len(str) <=1:
yield str
else:
for perm in all_perms(str[1:]):
for i in range(len(perm) +1):
#nb str[0:1] works in both string and list contexts
yield perm[:i] + str[0:1] + perm[i:]

def checkOrder(x, y):
x_votes = 0
y_votes = 0

if group1.index(x) < group1.index(y) :
x_votes += group1[4]
else:
y_votes += group1[4]

if group2.index(x) < group2.index(y) :
x_votes += group2[4]
else:
y_votes += group2[4]

if group3.index(x) < group3.index(y) :
x_votes += group3[4]
else:
y_votes += group3[4]

if group4.index(x) < group4.index(y) :
x_votes += group4[4]
else:
y_votes += group4[4]

if x_votes > y_votes:
return x
else:
return y

for order in all_perms(props ):
# if reduce(checkOrd er, order) == 'A':
# print 'A wins:'
# print order
# if reduce(checkOrd er, order) == 'B':
# print 'B wins:'
# print order
if reduce(checkOrd er, order) == 'C':
print 'C wins:'
print order
# if reduce(checkOrd er, order) == 'D':
# print 'D wins:'
# print order


I don't think you need all those 'ifs'.

groups = [group1, group2, group3, group4]

def checkOrder(x, y):
x_votes = 0
y_votes = 0
for group in groups:
if group.index(x) < group.index(y):
x_votes += group[4]
else:
y_votes += group[4]

for order in all_perms(props ):
winner = reduce(checkOrd er, order)
print '%s wins!' % winner
print order

Gerard

Apr 28 '06 #4
Gerard Flanagan wrote:
I don't think you need all those 'ifs'.

groups = [group1, group2, group3, group4]

def checkOrder(x, y):
x_votes = 0
y_votes = 0
for group in groups:
if group.index(x) < group.index(y):
x_votes += group[4]
else:
y_votes += group[4]

for order in all_perms(props ):
winner = reduce(checkOrd er, order)
print '%s wins!' % winner
print order


Nice. I was shuddering as I copy and pasted each if block. :)
Apr 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
488
by: Gernot Frisch | last post by:
hi, i don't even know how to desribe the error... I have a Qt application. Now, there's a .cpp file that I reduced to: // #include <somefile.h> int i=45; /* long source code
6
4756
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
1
3593
by: iam247 | last post by:
Hi I have a web page which receives information from a form (using request.form) and also attempts to look at an Access query to read in recoeds to a variable named rsGroup. When I have the following line commented, so it does not activate, I can successfully print all of the response.write's below: rsGroup.Open strSQL, adoCon
4
20567
by: rex64 | last post by:
I am getting an error message and I have not been able to figure hot how to fix it. I have done some research with no answers yet. I found this code that may help? Not sure what to do with it. using (StreamWriter sw = new StreamWriter (fullAddress , false, Encoding.UTF7)) Error message::::::::::::::::::::::::::::::::::::::::::::::
5
1156
by: Chad | last post by:
Hi, I have the following server code that attaches a client side script to the Update command of the data grid. Private Sub clientExc_ItemCreated(ByVal sender As Object, _ ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles clientExc.ItemCreated If e.Item.ItemType = ListItemType.EditItem Then CType(e.Item.Cells(4).Controls(0),
1
4826
by: Bruce | last post by:
Hello, I know this must be something simple I'm overlooking but I can't get err.raise inside a class to return anything but 440 - automation error. For example, if I create the following test class: Option Compare Database Option Explicit Private Sub Class_Initialize()
1
1126
by: shara | last post by:
Hello there, Can anybody please help me with this.I've a php code in which i've commneted certain part of the code .But still i'm getting a message that there is an error in that commented part.I tried removing the commented part completely but still getting an error message that there is an error at the line after the last line of the code.Can you please suggest me what could be the possible reason for this. Thanks in advance, Shara.
3
4288
by: christianlott1 | last post by:
I wouldn't have brought this up except that a friend had a similar problem as well. Situation: Code works fine for months, then suddenly breaks. In my case the code broke on a piece of commented out code on an event stub. The After Update stub was written but the one line piece of code was commented out.
3
1265
by: Fabio | last post by:
Why this code <?php function X() { // echo("commented ?>"); } X(); ?>
0
9671
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10433
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10161
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9035
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.