From 5d1f72604d6e36ffbc83a6b16f79086e360b0546 Mon Sep 17 00:00:00 2001 From: Parth Shandilya Date: Fri, 19 Oct 2018 14:00:31 +0530 Subject: [PATCH] Improved Code and removed Warnings (#483) --- Graphs/basic-graphs.py | 2 +- Graphs/minimum_spanning_tree_kruskal.py | 4 ++-- Graphs/scc_kosaraju.py | 4 ++-- Maths/SieveOfEratosthenes.py | 2 +- Neural_Network/perceptron.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 | 2 +- Project Euler/Problem 04/sol2.py | 2 +- Project Euler/Problem 05/sol1.py | 2 +- Project Euler/Problem 05/sol2.py | 2 +- Project Euler/Problem 06/sol1.py | 2 +- Project Euler/Problem 06/sol2.py | 2 +- Project Euler/Problem 07/sol1.py | 2 +- 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 +- boolean_algebra/Quine_McCluskey/QuineMcCluskey.py | 4 ++-- ciphers/affine_cipher.py | 6 +++--- ciphers/brute-force_caesar_cipher.py | 2 +- ciphers/caesar_cipher.py | 10 +++++----- ciphers/rsa_cipher.py | 2 +- ciphers/simple_substitution_cipher.py | 4 ++-- ciphers/transposition_cipher.py | 6 +++--- ciphers/transposition_cipher_encrypt-decrypt_file.py | 6 +++--- ciphers/vigenere_cipher.py | 6 +++--- data_structures/Graph/BellmanFord.py | 12 ++++++------ data_structures/Graph/Dijkstra.py | 12 ++++++------ data_structures/Graph/FloydWarshall.py | 10 +++++----- machine_learning/perceptron.py | 2 +- other/nested_brackets.py | 2 +- other/tower_of_hanoi.py | 2 +- 36 files changed, 67 insertions(+), 67 deletions(-) diff --git a/Graphs/basic-graphs.py b/Graphs/basic-graphs.py index 28fa3d180..c9a269f1a 100644 --- a/Graphs/basic-graphs.py +++ b/Graphs/basic-graphs.py @@ -168,7 +168,7 @@ def topo(G, ind=None, Q=[1]): def adjm(): - n, a = input(), [] + n, a = raw_input(), [] for i in xrange(n): a.append(map(int, raw_input().split())) return a, n diff --git a/Graphs/minimum_spanning_tree_kruskal.py b/Graphs/minimum_spanning_tree_kruskal.py index 81d64f421..930aab225 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,input().split())) +num_nodes, num_edges = list(map(int,raw_input().split())) edges = [] for i in range(num_edges): - node1, node2, cost = list(map(int,input().split())) + node1, node2, cost = list(map(int,raw_input().split())) edges.append((i,node1,node2,cost)) edges = sorted(edges, key=lambda edge: edge[3]) diff --git a/Graphs/scc_kosaraju.py b/Graphs/scc_kosaraju.py index 1f13ebaba..90d3568fa 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,input().split())) +n, m = list(map(int,raw_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,input().split())) + u, v = list(map(int,raw_input().split())) g[u].append(v) r[v].append(u) diff --git a/Maths/SieveOfEratosthenes.py b/Maths/SieveOfEratosthenes.py index bac4341de..2b132405a 100644 --- a/Maths/SieveOfEratosthenes.py +++ b/Maths/SieveOfEratosthenes.py @@ -1,5 +1,5 @@ import math -n = int(input("Enter n: ")) +n = int(raw_input("Enter n: ")) def sieve(n): l = [True] * (n+1) diff --git a/Neural_Network/perceptron.py b/Neural_Network/perceptron.py index 44c98e29c..16e632f8d 100644 --- a/Neural_Network/perceptron.py +++ b/Neural_Network/perceptron.py @@ -120,5 +120,5 @@ network.trannig() while True: sample = [] for i in range(3): - sample.insert(i, float(input('value: '))) + sample.insert(i, float(raw_input('value: '))) network.sort(sample) diff --git a/Project Euler/Problem 02/sol3.py b/Project Euler/Problem 02/sol3.py index d36b741bb..ede5e196b 100644 --- a/Project Euler/Problem 02/sol3.py +++ b/Project Euler/Problem 02/sol3.py @@ -7,7 +7,7 @@ By considering the terms in the Fibonacci sequence whose values do not exceed n, e.g. for n=10, we have {2,8}, sum is 10. ''' """Python 3""" -n = int(input()) +n = int(raw_input()) a=0 b=2 count=0 diff --git a/Project Euler/Problem 03/sol1.py b/Project Euler/Problem 03/sol1.py index bb9f8ca9a..72aed48b8 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(input()) +n=int(raw_input()) if(isprime(n)): print(n) else: diff --git a/Project Euler/Problem 03/sol2.py b/Project Euler/Problem 03/sol2.py index af4365b7b..eb5a2e9d9 100644 --- a/Project Euler/Problem 03/sol2.py +++ b/Project Euler/Problem 03/sol2.py @@ -4,7 +4,7 @@ The prime factors of 13195 are 5,7,13 and 29. What is the largest prime factor o e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17. ''' from __future__ import print_function -n=int(input()) +n=int(raw_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 77135ec7f..27490130c 100644 --- a/Project Euler/Problem 04/sol1.py +++ b/Project Euler/Problem 04/sol1.py @@ -4,7 +4,7 @@ A palindromic number reads the same both ways. The largest palindrome made from 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(input("limit? ")) +limit = int(raw_input("limit? ")) # fetchs the next number for number in range(limit-1,10000,-1): diff --git a/Project Euler/Problem 04/sol2.py b/Project Euler/Problem 04/sol2.py index e27e7d304..a7e486d38 100644 --- a/Project Euler/Problem 04/sol2.py +++ b/Project Euler/Problem 04/sol2.py @@ -12,7 +12,7 @@ for i in range(999,100,-1): arr.append(i*j) arr.sort() -n=int(input()) +n=int(raw_input()) for i in arr[::-1]: if(i?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~""" def main(): - message = input('Enter message: ') - key = int(input('Enter key [2000 - 9000]: ')) - mode = input('Encrypt/Decrypt [E/D]: ') + message = raw_input('Enter message: ') + key = int(raw_input('Enter key [2000 - 9000]: ')) + mode = raw_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 3b0716442..8582249c8 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 = input("Encrypted message: ") + message = raw_input("Encrypted message: ") message = message.upper() decrypt(message) diff --git a/ciphers/caesar_cipher.py b/ciphers/caesar_cipher.py index 6cd35e73d..19d4478e6 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 = input("What would you like to do?: ") + choice = raw_input("What would you like to do?: ") if choice not in ['1', '2', '3', '4']: print ("Invalid choice") elif choice == '1': - strng = input("Please enter the string to be ecrypted: ") + strng = raw_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 = input("Please enter the string to be decrypted: ") + strng = raw_input("Please enter the string to be decrypted: ") while True: - key = int(input("Please enter off-set between 1-94: ")) + 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 = input("Please enter the string to be decrypted: ") + strng = raw_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 94f69ddc2..ab8329428 100644 --- a/ciphers/rsa_cipher.py +++ b/ciphers/rsa_cipher.py @@ -6,7 +6,7 @@ BYTE_SIZE = 256 def main(): filename = 'encrypted_file.txt' - response = input('Encrypte\Decrypt [e\d]: ') + response = raw_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 1bdd7dc04..fe013cd58 100644 --- a/ciphers/simple_substitution_cipher.py +++ b/ciphers/simple_substitution_cipher.py @@ -4,9 +4,9 @@ import sys, random LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' def main(): - message = input('Enter message: ') + message = raw_input('Enter message: ') key = 'LFWOAYUISVKMNXPBDCRJTQEGHZ' - resp = input('Encrypt/Decrypt [e/d]: ') + resp = raw_input('Encrypt/Decrypt [e/d]: ') checkValidKey(key) diff --git a/ciphers/transposition_cipher.py b/ciphers/transposition_cipher.py index dbb358315..07f58c632 100644 --- a/ciphers/transposition_cipher.py +++ b/ciphers/transposition_cipher.py @@ -2,9 +2,9 @@ from __future__ import print_function import math def main(): - message = input('Enter message: ') - key = int(input('Enter key [2-%s]: ' % (len(message) - 1))) - mode = input('Encryption/Decryption [e/d]: ') + message = raw_input('Enter message: ') + key = int(raw_input('Enter key [2-%s]: ' % (len(message) - 1))) + mode = raw_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 57620d839..5c3eaaca6 100644 --- a/ciphers/transposition_cipher_encrypt-decrypt_file.py +++ b/ciphers/transposition_cipher_encrypt-decrypt_file.py @@ -5,15 +5,15 @@ import transposition_cipher as transCipher def main(): inputFile = 'Prehistoric Men.txt' outputFile = 'Output.txt' - key = int(input('Enter key: ')) - mode = input('Encrypt/Decrypt [e/d]: ') + key = int(raw_input('Enter key: ')) + mode = raw_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 = input('> ') + response = raw_input('> ') if not response.lower().startswith('y'): sys.exit() diff --git a/ciphers/vigenere_cipher.py b/ciphers/vigenere_cipher.py index 5d5be0792..34f49c3c0 100644 --- a/ciphers/vigenere_cipher.py +++ b/ciphers/vigenere_cipher.py @@ -2,9 +2,9 @@ from __future__ import print_function LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' def main(): - message = input('Enter message: ') - key = input('Enter key [alphanumeric]: ') - mode = input('Encrypt/Decrypt [e/d]: ') + message = raw_input('Enter message: ') + key = raw_input('Enter key [alphanumeric]: ') + mode = raw_input('Encrypt/Decrypt [e/d]: ') if mode.lower().startswith('e'): mode = 'encrypt' diff --git a/data_structures/Graph/BellmanFord.py b/data_structures/Graph/BellmanFord.py index 82db80546..f5e1ac983 100644 --- a/data_structures/Graph/BellmanFord.py +++ b/data_structures/Graph/BellmanFord.py @@ -35,8 +35,8 @@ def BellmanFord(graph, V, E, src): #MAIN -V = int(input("Enter number of vertices: ")) -E = int(input("Enter number of edges: ")) +V = int(raw_input("Enter number of vertices: ")) +E = int(raw_input("Enter number of edges: ")) graph = [dict() for j in range(E)] @@ -45,10 +45,10 @@ for i in range(V): for i in range(E): print("\nEdge ",i+1) - src = int(input("Enter source:")) - dst = int(input("Enter destination:")) - weight = float(input("Enter weight:")) + src = int(raw_input("Enter source:")) + dst = int(raw_input("Enter destination:")) + weight = float(raw_input("Enter weight:")) graph[i] = {"src": src,"dst": dst, "weight": weight} -gsrc = int(input("\nEnter shortest path source:")) +gsrc = int(raw_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 891717141..2580dd2f0 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(input("Enter number of vertices: ")) -E = int(input("Enter number of edges: ")) +V = int(raw_input("Enter number of vertices: ")) +E = int(raw_input("Enter number of edges: ")) graph = [[float('inf') for i in range(V)] for j in range(V)] @@ -48,10 +48,10 @@ for i in range(V): for i in range(E): print("\nEdge ",i+1) - src = int(input("Enter source:")) - dst = int(input("Enter destination:")) - weight = float(input("Enter weight:")) + src = int(raw_input("Enter source:")) + dst = int(raw_input("Enter destination:")) + weight = float(raw_input("Enter weight:")) graph[src][dst] = weight -gsrc = int(input("\nEnter shortest path source:")) +gsrc = int(raw_input("\nEnter shortest path source:")) Dijkstra(graph, V, gsrc) diff --git a/data_structures/Graph/FloydWarshall.py b/data_structures/Graph/FloydWarshall.py index fae8b19b3..64d41c2f8 100644 --- a/data_structures/Graph/FloydWarshall.py +++ b/data_structures/Graph/FloydWarshall.py @@ -30,8 +30,8 @@ def FloydWarshall(graph, V): #MAIN -V = int(input("Enter number of vertices: ")) -E = int(input("Enter number of edges: ")) +V = int(raw_input("Enter number of vertices: ")) +E = int(raw_input("Enter number of edges: ")) graph = [[float('inf') for i in range(V)] for j in range(V)] @@ -40,9 +40,9 @@ for i in range(V): for i in range(E): print("\nEdge ",i+1) - src = int(input("Enter source:")) - dst = int(input("Enter destination:")) - weight = float(input("Enter weight:")) + src = int(raw_input("Enter source:")) + dst = int(raw_input("Enter destination:")) + weight = float(raw_input("Enter weight:")) graph[src][dst] = weight FloydWarshall(graph, V) diff --git a/machine_learning/perceptron.py b/machine_learning/perceptron.py index 8ac3e8fc6..86556f2e5 100644 --- a/machine_learning/perceptron.py +++ b/machine_learning/perceptron.py @@ -120,5 +120,5 @@ network.trannig() while True: sample = [] for i in range(3): - sample.insert(i, float(input('value: '))) + sample.insert(i, float(raw_input('value: '))) network.sort(sample) \ No newline at end of file diff --git a/other/nested_brackets.py b/other/nested_brackets.py index 76677d564..17ca01161 100644 --- a/other/nested_brackets.py +++ b/other/nested_brackets.py @@ -37,7 +37,7 @@ def is_balanced(S): def main(): - S = input("Enter sequence of brackets: ") + S = raw_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 dc15b2ce8..92c331564 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(input('Height of hanoi: ')) + height = int(raw_input('Height of hanoi: ')) moveTower(height, 'A', 'B', 'C') if __name__ == '__main__':