Skip to content

Made the code Python 3 compatible #407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 4, 2018

Conversation

s-sanyal
Copy link
Contributor

@s-sanyal s-sanyal commented Oct 3, 2018

No description provided.

@cclauss
Copy link
Member

cclauss commented Oct 3, 2018

Not quite right...

$ python2 -c "for x in 'abc': print (x),"

a b c

$ python3 -c "for x in 'abc': print (x),"

a
b
c

See #405

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like #405 to keep all the items on one line.

@cclauss
Copy link
Member

cclauss commented Oct 3, 2018

Now it works great in Python 3 but it is now a syntax error in Python 2. You need to add from __future__ import print_function at the top of the file before any other imports.

@harshildarji
Copy link
Member

@cclauss @s-sanyal It still gives syntax error while executing with Python 2!

@@ -37,7 +38,7 @@ def calculateSpan(price, S):
# A utility function to print elements of array
def printArray(arr, n):
for i in range(0,n):
print arr[i],
print (arr[i],end =" ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete the space... print (arr[i],end =" ") --> print(arr[i], end=" ")

print() is now a function like all other functions so it should be formatted in the same way.

@cclauss
Copy link
Member

cclauss commented Oct 4, 2018

@ harshildarji Do you have from __future__ import print_function at the top of your file above all other imports? What is the full text of the error that you are seeing?

Changed two characters which were the root cause of 'SyntaxError: Non-ASCII character '\xe2' in file main.py, but no encoding declared'
@harshildarji
Copy link
Member

@cclauss The problem was in the explanation part at the very beginning of the script. But now it's solved, so I'm merging this PR now.

@harshildarji harshildarji merged commit c8e7a65 into TheAlgorithms:master Oct 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants