ZoranPandovski / al-go-rithms

:musical_note: Algorithms written in different programming languages - https://zoranpandovski.github.io/al-go-rithms/
Creative Commons Zero v1.0 Universal
1.33k stars 1.95k forks source link

print() is a function in Python 3 #1515

Closed cclauss closed 5 years ago

cclauss commented 5 years ago

flake8 testing of https://github.com/ZoranPandovski/al-go-rithms on Python 3.7.0

$ flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics

./data_structures/Graphs/graphsearch/stronglyConnectedComponents/python/kosaraju_algo.py:20:15: E999 SyntaxError: invalid syntax
        print v,
              ^
./data_structures/b_tree/Python/sum_root_leaf.py:46:14: E999 SyntaxError: invalid syntax
    print path
             ^
./data_structures/b_tree/Python/bfs.py:26:16: E999 SyntaxError: invalid syntax
    print result
               ^
./data_structures/b_tree/Python/binary_search_tree.py:29:22: E999 SyntaxError: invalid syntax
            print root.val
                     ^
./data_structures/b_tree/Python/binaryTree.py:61:18: E999 SyntaxError: invalid syntax
        print root.val
                 ^
./data_structures/b_tree/Python/print_tree_bfs.py:33:24: E999 SyntaxError: invalid syntax
            print popped.val, ' ',
                       ^
./data_structures/avl_tree/Python/avl.py:8:17: E999 SyntaxError: invalid syntax
        print msg
                ^
./data_structures/dictionary/python/dictionaries.py:7:20: E999 SyntaxError: invalid syntax
    print dictionary
                   ^
./data_structures/Tree/python/tree_utils.py:14:12: E999 SyntaxError: invalid syntax
            print str(root.data)
           ^
./data_structures/Tree/python/identical_trees.py:30:34: E999 SyntaxError: invalid syntax
        print "Both trees are identical"
                                 ^
./data_structures/Tree/python/tree_basic_problems.py:59:17: E999 SyntaxError: invalid syntax
        print curr_node.data,
                ^
./data_structures/Tree/Binary-tree/python/BinaryTree.py:45:46: E999 SyntaxError: invalid syntax
    print 'Inorder traversal for binary tree:', inorder(root, [])
                                             ^
./cluster_analysis/dbscan/python/DBScan.py:18:8: E999 IndentationError: unexpected indent
        self._points = points
       ^
./graph/Python/BFS.py:35:10: E999 SyntaxError: invalid syntax
            print s,
         ^
./graph/Python/DFS.py:23:9: E999 SyntaxError: invalid syntax
        print v,
        ^
./graph/Python/tarjan-algo.py:39:11: E999 SyntaxError: invalid syntax
                print w, 
          ^
./graph/Python/prims-algorithm.py:15:29: E999 SyntaxError: invalid syntax
        print "Edge \tWeight"
                            ^
./graph/Python/topological_sort.py:41:19: E999 SyntaxError: invalid syntax
        print stack
                  ^
./machine_learning/Regression_exmaple/LINEAR_REGRESSION.py:91:48: E999 SyntaxError: EOL while scanning string literal
    print("Estimated coefficients:\nb_0 = {}  \ 
                                               ^
./puzzles/Tower_Of_Hanoi/Python/towerOfHanoi.py:8:27: E999 SyntaxError: invalid syntax
            print "moving " + str(disk) + " from " + source[1] + " to " + target[1]
                          ^
./backtracking/sudoku/python/sudoku.py:5:21: E999 SyntaxError: invalid syntax
            print arr[i][j],
                    ^
./backtracking/n-queens/Python/NQueen.py:10:14: E999 SyntaxError: invalid syntax
            print board[i][j],
             ^
./backtracking/m-coloring/Python/mColoring.py:37:64: E999 SyntaxError: invalid syntax
        print "Solution exist and Following are the assigned colours:"
                                                               ^
./backtracking/rat_in_a_maze/Python/rat_maze.py:6:14: E999 SyntaxError: invalid syntax
    print "\n"
             ^
./strings/string_fundamental/python/isogram.py:17:8: F821 undefined name 'is_anagram'
    if is_anagram:
       ^
./strings/string_search/Tries/python/trie.py:121:31: E999 SyntaxError: invalid syntax
    print "'goodbye' in trie: ", trie.has_word('goodbye')
                              ^
./synchronization/ProducerConsumer/Python/producer_consumer.py:20:49: E999 SyntaxError: invalid syntax
                print "Q full : producer waiting"
                                                ^
./dp/rod_cutting/python/rodCutting.py:8:12: F821 undefined name 'xrange'
        for i in xrange(1, n):
           ^
./dp/rod_cutting/python/rodCutting.py:16:10: F821 undefined name 'xrange'
for i in xrange(n):
         ^
./dp/coin_change/py/coin_change.py:22:35: E999 SyntaxError: invalid syntax
    print "No. of ways to change - {}".format(coin_change(coins, amount))
                                  ^
./dp/longest_common_subsequence/py/lcs.py:19:23: E999 SyntaxError: invalid syntax
print "LCS (Length) = ", lcs(X, Y)                      ^
./dp/Lowest_Common_Ancestor/Python/lcs.py:69:22: E999 SyntaxError: invalid syntax
print "LCA(4, 5) = %d" %(findLCA(root, 4, 5,))
                     ^
./dp/knapsack_problem/py/knapsack_problem.py:27:20: E999 SyntaxError: invalid syntax
    print "Result - {}".format(knapsack(weights, values, W))
                   ^
./dp/maximum_subarray_problem/python/Maximum_subarray_sum.py:21:12: E999 SyntaxError: invalid syntax
print output
           ^
./dp/EditDistance/Python/EditDistance.py:32:18: E999 SyntaxError: invalid syntax
print editDistance(str1, str2, len(str1), len(str2))
                 ^
./greedy/minimum_coins/python/minimum_coins.py:26:25: E999 SyntaxError: invalid syntax
            print message
                        ^
./greedy/dijkstra_shortest_path/python/dijkstra_shortest_path.py:16:13: F821 undefined name 'minimum_distance'
        u = minimum_distance(dist, Q)
            ^
./greedy/dijkstra_shortest_path/python/dijkstra_shortest_path.py:23:13: F821 undefined name 'get_neighbours'
        n = get_neighbours(graph, u)
            ^
./greedy/dijkstra_shortest_path/python/dijkstra_shortest_path.py:25:29: F821 undefined name 'dist_between'
            alt = dist[u] + dist_between(graph, u, vertex)
                            ^
./greedy/prim's_algorithm/python/prims_algorithm.py:12:29: E999 SyntaxError: invalid syntax
        print "Edge \tWeight"
                            ^
./principal_component_analysis/python/PCA.py:3:1: E999 SyntaxError: invalid syntax
%matplotlib inline
^
./cryptography/ElGamal/Python/ElGamal.py:39:34: E999 TabError: inconsistent use of tabs and spaces in indentation
    privKey = randint(1, curve.p - 1)
                                 ^
./cryptography/FourSquare_cipher/Python/FourSquare_cipher.py:60:16: E999 SyntaxError: invalid syntax
    print output
               ^
./cryptography/autokey_cipher/python/autokey.py:52:17: E999 SyntaxError: invalid syntax
    print ciphertext
                ^
./cryptography/hillcipher/Python/hiller.py:37:33: E999 SyntaxError: invalid syntax
        print "\nEnter a valid length!"
                                ^
./cryptography/runningkey_cipher/python/runningkey.py:54:17: E999 SyntaxError: invalid syntax
    print ciphertext
                ^
./cryptography/many_time_pad_attack/python/manyTimePad.py:80:17: E999 SyntaxError: invalid syntax
print cipherTexts
                ^
./cryptography/baconian_cipher/python/baconian.py:16:17: E999 SyntaxError: invalid syntax
    print ciphertext
                ^
./math/sum_of_digits/python/sum_of_digits.py:8:19: E999 SyntaxError: invalid syntax
print sum_of_digits(3)  #3
                  ^
./math/josepheus_problem/python/josephus.py:6:24: E999 SyntaxError: invalid syntax
        print "Player Died : " , list_of_players.pop(index)
                       ^
./math/pernicious_number/Python/pernicious.py:36:10: E999 TabError: inconsistent use of tabs and spaces in indentation
        return 1
         ^
./math/gauss_legendre/python/gauss_legendre.py:31:10: F821 undefined name 'xrange'
for i in xrange(1, num_iter+1):
         ^
./math/collatz_conjecture/Python/collatz_conjecture.py:14:17: E999 SyntaxError: invalid syntax
    print collatz(number)
                ^
./math/Prime_Factorization/Python/prime_factorization.py:18:9: F821 undefined name 'raw_input'
n = int(raw_input())
        ^
./math/prime_sieve/python/create_large_primes.py:24:30: E999 SyntaxError: invalid syntax
     return "Failure after "+`r_` + " tries."
                             ^
./math/fibonacci/python/fibonacci_memo.py:23:15: E999 SyntaxError: invalid syntax
print fibonacci(10)
              ^
./math/automorphic_numbers/python/automorphic.py:18:28: E999 SyntaxError: invalid syntax
        print "Automorphic Number"
                           ^
./math/strong_number/python/strong_number.py:3:4: E999 SyntaxError: invalid syntax
temp=num                                        # storing value of number in temporary variable as we need original later. 
   ^
./math/towers_of_Hanoi/python/tower_of_hanoi.py:2:5: F821 undefined name 'heigt'
    if(heigt>=1):
    ^
./sort/bucket_sort/python/bucket sort.py:11:5: F821 undefined name 'insertionsort'
    insertionsort( bucket )
    ^
./sort/merge_sort/python/haragg2_merge_sort.py:40:9: E999 SyntaxError: invalid syntax
print len(new_list)
        ^
./sort/merge_sort/python/merge_sort.py:36:20: E999 SyntaxError: invalid syntax
    print 'Sorted: ', sorted_list
                   ^
./sort/pigeonhole_sort/py/pigeonhole_sort.py:17:18: F821 undefined name 'xrange'
    for count in xrange(size):
                 ^
./sort/gnome_sort/py/gnome_sort.py:19:52: E999 SyntaxError: invalid syntax
print "Sorted seqquence after applying Gnome Sort :",
                                                   ^
./sort/Binary_Insertion_Sort/python/Binary_Insertion_Sort.py:49:9: E999 SyntaxError: invalid syntax
print BIS([37, 23, 0, 17, 45, 9, 80, 9, 9])
        ^
54    E999 SyntaxError: invalid syntax
11    F821 undefined name 'xrange'
65
Vivek-abstract commented 5 years ago

I think the code you're trying to run is for Python 2 as Python 3 has a syntax print() with braces and python 2 doesn't have those braces

ZoranPandovski commented 5 years ago

Yes, that is python 2 syntax. If we change them with print() as a function it will work for both Python 2 & 3

cclauss commented 5 years ago

There are a few subtle rules about commas, end=, file=, etc. to watch out for...