From ea2ddaaf6a8ec43391d135f8bd92108eb0083821 Mon Sep 17 00:00:00 2001 From: Alex Brown Date: Sat, 20 Oct 2018 14:45:08 -0500 Subject: [PATCH] all valid python 3 --- boolean_algebra/quine_mc_cluskey.py | 6 +- ciphers/affine_cipher.py | 6 +- ciphers/brute_force_caesar_cipher.py | 2 +- ciphers/caesar_cipher.py | 8 +- ciphers/rsa_cipher.py | 2 +- ciphers/simple_substitution_cipher.py | 4 +- ciphers/transposition_cipher.py | 6 +- ...ansposition_cipher_encrypt_decrypt_file.py | 6 +- ciphers/vigenere_cipher.py | 6 +- data_structures/graph/bellman_ford.py | 12 +- data_structures/graph/dijkstra.py | 12 +- data_structures/graph/floyd_warshall.py | 10 +- graphs/minimum_spanning_tree_kruskal.py | 4 +- graphs/minimum_spanning_tree_prims.py | 4 +- graphs/scc_kosaraju.py | 4 +- machine_learning/perceptron.py | 4 +- maths/sieve_of_eratosthenes.py | 4 +- neural_network/perceptron.py | 2 +- other/nested_brackets.py | 2 +- other/tower_of_hanoi.py | 2 +- project_euler/problem_02/sol3.py | 2 +- project_euler/problem_03/sol1.py | 2 +- project_euler/problem_03/sol2.py | 2 +- project_euler/problem_04/sol1.py | 4 +- project_euler/problem_04/sol2.py | 4 +- project_euler/problem_05/sol1.py | 4 +- project_euler/problem_05/sol2.py | 2 +- project_euler/problem_06/sol1.py | 4 +- project_euler/problem_06/sol2.py | 4 +- project_euler/problem_07/sol1.py | 4 +- project_euler/problem_07/sol2.py | 2 +- project_euler/problem_08/sol1.py | 2 +- project_euler/problem_09/sol2.py | 2 +- project_euler/problem_13/sol1.py | 4 +- project_euler/problem_16/sol1.py | 2 +- project_euler/problem_20/sol1.py | 2 +- tags | 1360 ----------------- 37 files changed, 76 insertions(+), 1436 deletions(-) delete mode 100644 tags diff --git a/boolean_algebra/quine_mc_cluskey.py b/boolean_algebra/quine_mc_cluskey.py index ff2df5117ce9..db4d153cbfd7 100644 --- a/boolean_algebra/quine_mc_cluskey.py +++ b/boolean_algebra/quine_mc_cluskey.py @@ -99,8 +99,8 @@ def prime_implicant_chart(prime_implicants, binary): return chart def main(): - no_of_variable = int(raw_input("Enter the no. of variables\n")) - minterms = [int(x) for x in raw_input("Enter the decimal representation of Minterms 'Spaces Seprated'\n").split()] + no_of_variable = int(input("Enter the no. of variables\n")) + minterms = [int(x) for x in input("Enter the decimal representation of Minterms 'Spaces Seprated'\n").split()] binary = decimal_to_binary(no_of_variable, minterms) prime_implicants = check(binary) @@ -113,4 +113,4 @@ def main(): print(essential_prime_implicants) if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/ciphers/affine_cipher.py b/ciphers/affine_cipher.py index a2d30b43a333..4fbe87d42e61 100644 --- a/ciphers/affine_cipher.py +++ b/ciphers/affine_cipher.py @@ -4,9 +4,9 @@ SYMBOLS = """ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~""" def main(): - message = raw_input('Enter message: ') - key = int(raw_input('Enter key [2000 - 9000]: ')) - mode = raw_input('Encrypt/Decrypt [E/D]: ') + message = input('Enter message: ') + key = int(input('Enter key [2000 - 9000]: ')) + mode = input('Encrypt/Decrypt [E/D]: ') if mode.lower().startswith('e'): mode = 'encrypt' diff --git a/ciphers/brute_force_caesar_cipher.py b/ciphers/brute_force_caesar_cipher.py index 8582249c8d27..3b0716442fc5 100644 --- a/ciphers/brute_force_caesar_cipher.py +++ b/ciphers/brute_force_caesar_cipher.py @@ -44,7 +44,7 @@ def decrypt(message): print("Decryption using Key #%s: %s" % (key, translated)) def main(): - message = raw_input("Encrypted message: ") + message = input("Encrypted message: ") message = message.upper() decrypt(message) diff --git a/ciphers/caesar_cipher.py b/ciphers/caesar_cipher.py index 19d4478e6b68..63c5a0608ee0 100644 --- a/ciphers/caesar_cipher.py +++ b/ciphers/caesar_cipher.py @@ -40,25 +40,25 @@ def main(): print("3.BruteForce") print("4.Quit") while True: - choice = raw_input("What would you like to do?: ") + choice = input("What would you like to do?: ") if choice not in ['1', '2', '3', '4']: print ("Invalid choice") elif choice == '1': - strng = raw_input("Please enter the string to be ecrypted: ") + strng = input("Please enter the string to be ecrypted: ") while True: key = int(input("Please enter off-set between 1-94: ")) if key in range(1, 95): print (encrypt(strng, key)) main() elif choice == '2': - strng = raw_input("Please enter the string to be decrypted: ") + strng = input("Please enter the string to be decrypted: ") while True: key = raw_int(input("Please enter off-set between 1-94: ")) if key > 0 and key <= 94: print(decrypt(strng, key)) main() elif choice == '3': - strng = raw_input("Please enter the string to be decrypted: ") + strng = input("Please enter the string to be decrypted: ") brute_force(strng) main() elif choice == '4': diff --git a/ciphers/rsa_cipher.py b/ciphers/rsa_cipher.py index ab8329428e95..94f69ddc2533 100644 --- a/ciphers/rsa_cipher.py +++ b/ciphers/rsa_cipher.py @@ -6,7 +6,7 @@ def main(): filename = 'encrypted_file.txt' - response = raw_input('Encrypte\Decrypt [e\d]: ') + response = input('Encrypte\Decrypt [e\d]: ') if response.lower().startswith('e'): mode = 'encrypt' diff --git a/ciphers/simple_substitution_cipher.py b/ciphers/simple_substitution_cipher.py index fe013cd58918..1bdd7dc04a57 100644 --- a/ciphers/simple_substitution_cipher.py +++ b/ciphers/simple_substitution_cipher.py @@ -4,9 +4,9 @@ LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' def main(): - message = raw_input('Enter message: ') + message = input('Enter message: ') key = 'LFWOAYUISVKMNXPBDCRJTQEGHZ' - resp = raw_input('Encrypt/Decrypt [e/d]: ') + resp = input('Encrypt/Decrypt [e/d]: ') checkValidKey(key) diff --git a/ciphers/transposition_cipher.py b/ciphers/transposition_cipher.py index 07f58c632639..dbb358315d22 100644 --- a/ciphers/transposition_cipher.py +++ b/ciphers/transposition_cipher.py @@ -2,9 +2,9 @@ import math def main(): - message = raw_input('Enter message: ') - key = int(raw_input('Enter key [2-%s]: ' % (len(message) - 1))) - mode = raw_input('Encryption/Decryption [e/d]: ') + message = input('Enter message: ') + key = int(input('Enter key [2-%s]: ' % (len(message) - 1))) + mode = input('Encryption/Decryption [e/d]: ') if mode.lower().startswith('e'): text = encryptMessage(key, message) diff --git a/ciphers/transposition_cipher_encrypt_decrypt_file.py b/ciphers/transposition_cipher_encrypt_decrypt_file.py index 5c3eaaca6e27..57620d83948c 100644 --- a/ciphers/transposition_cipher_encrypt_decrypt_file.py +++ b/ciphers/transposition_cipher_encrypt_decrypt_file.py @@ -5,15 +5,15 @@ def main(): inputFile = 'Prehistoric Men.txt' outputFile = 'Output.txt' - key = int(raw_input('Enter key: ')) - mode = raw_input('Encrypt/Decrypt [e/d]: ') + key = int(input('Enter key: ')) + mode = input('Encrypt/Decrypt [e/d]: ') if not os.path.exists(inputFile): print('File %s does not exist. Quitting...' % inputFile) sys.exit() if os.path.exists(outputFile): print('Overwrite %s? [y/n]' % outputFile) - response = raw_input('> ') + response = input('> ') if not response.lower().startswith('y'): sys.exit() diff --git a/ciphers/vigenere_cipher.py b/ciphers/vigenere_cipher.py index 34f49c3c018f..5d5be0792835 100644 --- a/ciphers/vigenere_cipher.py +++ b/ciphers/vigenere_cipher.py @@ -2,9 +2,9 @@ LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' def main(): - message = raw_input('Enter message: ') - key = raw_input('Enter key [alphanumeric]: ') - mode = raw_input('Encrypt/Decrypt [e/d]: ') + message = input('Enter message: ') + key = input('Enter key [alphanumeric]: ') + mode = input('Encrypt/Decrypt [e/d]: ') if mode.lower().startswith('e'): mode = 'encrypt' diff --git a/data_structures/graph/bellman_ford.py b/data_structures/graph/bellman_ford.py index f5e1ac9836cb..82db80546b94 100644 --- a/data_structures/graph/bellman_ford.py +++ b/data_structures/graph/bellman_ford.py @@ -35,8 +35,8 @@ def BellmanFord(graph, V, E, src): #MAIN -V = int(raw_input("Enter number of vertices: ")) -E = int(raw_input("Enter number of edges: ")) +V = int(input("Enter number of vertices: ")) +E = int(input("Enter number of edges: ")) graph = [dict() for j in range(E)] @@ -45,10 +45,10 @@ def BellmanFord(graph, V, E, src): for i in range(E): print("\nEdge ",i+1) - src = int(raw_input("Enter source:")) - dst = int(raw_input("Enter destination:")) - weight = float(raw_input("Enter weight:")) + src = int(input("Enter source:")) + dst = int(input("Enter destination:")) + weight = float(input("Enter weight:")) graph[i] = {"src": src,"dst": dst, "weight": weight} -gsrc = int(raw_input("\nEnter shortest path source:")) +gsrc = int(input("\nEnter shortest path source:")) BellmanFord(graph, V, E, gsrc) diff --git a/data_structures/graph/dijkstra.py b/data_structures/graph/dijkstra.py index 2580dd2f00fc..8917171417c4 100644 --- a/data_structures/graph/dijkstra.py +++ b/data_structures/graph/dijkstra.py @@ -38,8 +38,8 @@ def Dijkstra(graph, V, src): #MAIN -V = int(raw_input("Enter number of vertices: ")) -E = int(raw_input("Enter number of edges: ")) +V = int(input("Enter number of vertices: ")) +E = int(input("Enter number of edges: ")) graph = [[float('inf') for i in range(V)] for j in range(V)] @@ -48,10 +48,10 @@ def Dijkstra(graph, V, src): for i in range(E): print("\nEdge ",i+1) - src = int(raw_input("Enter source:")) - dst = int(raw_input("Enter destination:")) - weight = float(raw_input("Enter weight:")) + src = int(input("Enter source:")) + dst = int(input("Enter destination:")) + weight = float(input("Enter weight:")) graph[src][dst] = weight -gsrc = int(raw_input("\nEnter shortest path source:")) +gsrc = int(input("\nEnter shortest path source:")) Dijkstra(graph, V, gsrc) diff --git a/data_structures/graph/floyd_warshall.py b/data_structures/graph/floyd_warshall.py index 64d41c2f88e1..fae8b19b351a 100644 --- a/data_structures/graph/floyd_warshall.py +++ b/data_structures/graph/floyd_warshall.py @@ -30,8 +30,8 @@ def FloydWarshall(graph, V): #MAIN -V = int(raw_input("Enter number of vertices: ")) -E = int(raw_input("Enter number of edges: ")) +V = int(input("Enter number of vertices: ")) +E = int(input("Enter number of edges: ")) graph = [[float('inf') for i in range(V)] for j in range(V)] @@ -40,9 +40,9 @@ def FloydWarshall(graph, V): for i in range(E): print("\nEdge ",i+1) - src = int(raw_input("Enter source:")) - dst = int(raw_input("Enter destination:")) - weight = float(raw_input("Enter weight:")) + src = int(input("Enter source:")) + dst = int(input("Enter destination:")) + weight = float(input("Enter weight:")) graph[src][dst] = weight FloydWarshall(graph, V) diff --git a/graphs/minimum_spanning_tree_kruskal.py b/graphs/minimum_spanning_tree_kruskal.py index 930aab2251c4..81d64f421a31 100644 --- a/graphs/minimum_spanning_tree_kruskal.py +++ b/graphs/minimum_spanning_tree_kruskal.py @@ -1,10 +1,10 @@ from __future__ import print_function -num_nodes, num_edges = list(map(int,raw_input().split())) +num_nodes, num_edges = list(map(int,input().split())) edges = [] for i in range(num_edges): - node1, node2, cost = list(map(int,raw_input().split())) + node1, node2, cost = list(map(int,input().split())) edges.append((i,node1,node2,cost)) edges = sorted(edges, key=lambda edge: edge[3]) diff --git a/graphs/minimum_spanning_tree_prims.py b/graphs/minimum_spanning_tree_prims.py index 569e73e0ab7b..7b1ad0e743f7 100644 --- a/graphs/minimum_spanning_tree_prims.py +++ b/graphs/minimum_spanning_tree_prims.py @@ -101,8 +101,8 @@ def deleteMinimum(heap, positions): return TreeEdges # < --------- Prims Algorithm --------- > -n = int(raw_input("Enter number of vertices: ")) -e = int(raw_input("Enter number of edges: ")) +n = int(input("Enter number of vertices: ")) +e = int(input("Enter number of edges: ")) adjlist = defaultdict(list) for x in range(e): l = [int(x) for x in input().split()] diff --git a/graphs/scc_kosaraju.py b/graphs/scc_kosaraju.py index 90d3568fa496..1f13ebaba36b 100644 --- a/graphs/scc_kosaraju.py +++ b/graphs/scc_kosaraju.py @@ -1,12 +1,12 @@ from __future__ import print_function # n - no of nodes, m - no of edges -n, m = list(map(int,raw_input().split())) +n, m = list(map(int,input().split())) g = [[] for i in range(n)] #graph r = [[] for i in range(n)] #reversed graph # input graph data (edges) for i in range(m): - u, v = list(map(int,raw_input().split())) + u, v = list(map(int,input().split())) g[u].append(v) r[v].append(u) diff --git a/machine_learning/perceptron.py b/machine_learning/perceptron.py index 86556f2e5485..fe1032aff4af 100644 --- a/machine_learning/perceptron.py +++ b/machine_learning/perceptron.py @@ -120,5 +120,5 @@ def sign(self, u): while True: sample = [] for i in range(3): - sample.insert(i, float(raw_input('value: '))) - network.sort(sample) \ No newline at end of file + sample.insert(i, float(input('value: '))) + network.sort(sample) diff --git a/maths/sieve_of_eratosthenes.py b/maths/sieve_of_eratosthenes.py index 2b132405ae4d..26c17fa6ffec 100644 --- a/maths/sieve_of_eratosthenes.py +++ b/maths/sieve_of_eratosthenes.py @@ -1,5 +1,5 @@ import math -n = int(raw_input("Enter n: ")) +n = int(input("Enter n: ")) def sieve(n): l = [True] * (n+1) @@ -21,4 +21,4 @@ def sieve(n): return prime print(sieve(n)) - \ No newline at end of file + diff --git a/neural_network/perceptron.py b/neural_network/perceptron.py index 16e632f8db4a..44c98e29c52b 100644 --- a/neural_network/perceptron.py +++ b/neural_network/perceptron.py @@ -120,5 +120,5 @@ def sign(self, u): while True: sample = [] for i in range(3): - sample.insert(i, float(raw_input('value: '))) + sample.insert(i, float(input('value: '))) network.sort(sample) diff --git a/other/nested_brackets.py b/other/nested_brackets.py index 17ca011610b9..76677d56439a 100644 --- a/other/nested_brackets.py +++ b/other/nested_brackets.py @@ -37,7 +37,7 @@ def is_balanced(S): def main(): - S = raw_input("Enter sequence of brackets: ") + S = input("Enter sequence of brackets: ") if is_balanced(S): print((S, "is balanced")) diff --git a/other/tower_of_hanoi.py b/other/tower_of_hanoi.py index 92c33156438c..dc15b2ce8e58 100644 --- a/other/tower_of_hanoi.py +++ b/other/tower_of_hanoi.py @@ -19,7 +19,7 @@ def moveDisk(fp,tp): print(('moving disk from', fp, 'to', tp)) def main(): - height = int(raw_input('Height of hanoi: ')) + height = int(input('Height of hanoi: ')) moveTower(height, 'A', 'B', 'C') if __name__ == '__main__': diff --git a/project_euler/problem_02/sol3.py b/project_euler/problem_02/sol3.py index ede5e196ba7d..d36b741bb4f9 100644 --- a/project_euler/problem_02/sol3.py +++ b/project_euler/problem_02/sol3.py @@ -7,7 +7,7 @@ e.g. for n=10, we have {2,8}, sum is 10. ''' """Python 3""" -n = int(raw_input()) +n = int(input()) a=0 b=2 count=0 diff --git a/project_euler/problem_03/sol1.py b/project_euler/problem_03/sol1.py index 72aed48b8d90..bb9f8ca9ad12 100644 --- a/project_euler/problem_03/sol1.py +++ b/project_euler/problem_03/sol1.py @@ -19,7 +19,7 @@ def isprime(no): return True maxNumber = 0 -n=int(raw_input()) +n=int(input()) if(isprime(n)): print(n) else: diff --git a/project_euler/problem_03/sol2.py b/project_euler/problem_03/sol2.py index eb5a2e9d93b2..af4365b7b18f 100644 --- a/project_euler/problem_03/sol2.py +++ b/project_euler/problem_03/sol2.py @@ -4,7 +4,7 @@ e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17. ''' from __future__ import print_function -n=int(raw_input()) +n=int(input()) prime=1 i=2 while(i*i<=n): diff --git a/project_euler/problem_04/sol1.py b/project_euler/problem_04/sol1.py index 27490130c5c8..05fdd9ebab55 100644 --- a/project_euler/problem_04/sol1.py +++ b/project_euler/problem_04/sol1.py @@ -4,7 +4,7 @@ Find the largest palindrome made from the product of two 3-digit numbers which is less than N. ''' from __future__ import print_function -limit = int(raw_input("limit? ")) +limit = int(input("limit? ")) # fetchs the next number for number in range(limit-1,10000,-1): @@ -26,4 +26,4 @@ print(number) exit(0) - divisor -=1 \ No newline at end of file + divisor -=1 diff --git a/project_euler/problem_04/sol2.py b/project_euler/problem_04/sol2.py index a7e486d38e5a..68284ed3435c 100644 --- a/project_euler/problem_04/sol2.py +++ b/project_euler/problem_04/sol2.py @@ -12,8 +12,8 @@ arr.append(i*j) arr.sort() -n=int(raw_input()) +n=int(input()) for i in arr[::-1]: if(i?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnop/;" v -Search Algorithms README.md /^## Search Algorithms$/;" s -SegmentTree data_structures/binary tree/lazy_segment_tree.py /^class SegmentTree:$/;" c -Selection README.md /^### Selection$/;" S -SendFile file_transfer_protocol/ftp_send_receive.py /^def SendFile():$/;" f -Shell README.md /^### Shell$/;" S -Sort Algorithms README.md /^## Sort Algorithms$/;" s -Source: [Wikipedia](https://en.wikipedia.org/wiki/Caesar_cipher) README.md /^###### Source: [Wikipedia](https:\/\/en.wikipedia.org\/wiki\/Caesar_cipher)$/;" u -Source: [Wikipedia](https://en.wikipedia.org/wiki/Interpolation_search) README.md /^###### Source: [Wikipedia](https:\/\/en.wikipedia.org\/wiki\/Interpolation_search)$/;" u -Source: [Wikipedia](https://en.wikipedia.org/wiki/Jump_search) README.md /^###### Source: [Wikipedia](https:\/\/en.wikipedia.org\/wiki\/Jump_search)$/;" u -Source: [Wikipedia](https://en.wikipedia.org/wiki/Quickselect) README.md /^###### Source: [Wikipedia](https:\/\/en.wikipedia.org\/wiki\/Quickselect)$/;" u -Source: [Wikipedia](https://en.wikipedia.org/wiki/ROT13) README.md /^###### Source: [Wikipedia](https:\/\/en.wikipedia.org\/wiki\/ROT13)$/;" u -Source: [Wikipedia](https://en.wikipedia.org/wiki/RSA_(cryptosystem)) README.md /^###### Source: [Wikipedia](https:\/\/en.wikipedia.org\/wiki\/RSA_(cryptosystem))$/;" u -Source: [Wikipedia](https://en.wikipedia.org/wiki/Tabu_search) README.md /^###### Source: [Wikipedia](https:\/\/en.wikipedia.org\/wiki\/Tabu_search)$/;" u -Source: [Wikipedia](https://en.wikipedia.org/wiki/Transposition_cipher) README.md /^###### Source: [Wikipedia](https:\/\/en.wikipedia.org\/wiki\/Transposition_cipher)$/;" u -Source: [Wikipedia](https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher) README.md /^###### Source: [Wikipedia](https:\/\/en.wikipedia.org\/wiki\/Vigen%C3%A8re_cipher)$/;" u -Source: [Wikipedia](https://en.wikipedia.org/wiki/XOR_cipher) README.md /^###### Source: [Wikipedia](https:\/\/en.wikipedia.org\/wiki\/XOR_cipher)$/;" u -Stack data_structures/stacks/__init__.py /^class Stack:$/;" c -Stack data_structures/stacks/stack.py /^class Stack(object):$/;" c -StackOverflowError data_structures/stacks/stack.py /^class StackOverflowError(BaseException):$/;" c -SubArray dynamic_programming/longest_sub_array.py /^class SubArray:$/;" c -T project_euler/problem_02/sol2.py /^T = int(input().strip())$/;" v -TAG machine_learning/k_means_clust.py /^TAG = 'K-MEANS-CLUST\/ '$/;" v -TEST_FILE searches/test_tabu_search.py /^TEST_FILE = os.path.join(os.path.dirname(__file__), '.\/tabu_test_data.txt')$/;" v -TFKMeansCluster dynamic_programming/k_means_clustering_tensorflow.py /^def TFKMeansCluster(vectors, noofclusters):$/;" f -Tabu README.md /^## Tabu$/;" s -Test linear_algebra_python/src/tests.py /^class Test(unittest.TestCase):$/;" c -TestClass searches/test_tabu_search.py /^class TestClass(unittest.TestCase):$/;" c -TestUnionFind data_structures/union_find/tests_union_find.py /^class TestUnionFind(unittest.TestCase):$/;" c -Tests linear_algebra_python/README.md /^## Tests $/;" s -The Algorithms - Python README.md /^# The Algorithms - Python