Skip to content

Improved Code and removed Warnings #483

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 1 commit into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Graphs/basic-graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Graphs/minimum_spanning_tree_kruskal.py
Original file line number Diff line number Diff line change
@@ -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])
Expand Down
4 changes: 2 additions & 2 deletions Graphs/scc_kosaraju.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion Maths/SieveOfEratosthenes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import math
n = int(input("Enter n: "))
n = int(raw_input("Enter n: "))

def sieve(n):
l = [True] * (n+1)
Expand Down
2 changes: 1 addition & 1 deletion Neural_Network/perceptron.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ def sign(self, u):
while True:
sample = []
for i in range(3):
sample.insert(i, float(input('value: ')))
sample.insert(i, float(raw_input('value: ')))
network.sort(sample)
2 changes: 1 addition & 1 deletion Project Euler/Problem 02/sol3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion Project Euler/Problem 03/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def isprime(no):
return True

maxNumber = 0
n=int(input())
n=int(raw_input())
if(isprime(n)):
print(n)
else:
Expand Down
2 changes: 1 addition & 1 deletion Project Euler/Problem 03/sol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(input())
n=int(raw_input())
prime=1
i=2
while(i*i<=n):
Expand Down
2 changes: 1 addition & 1 deletion Project Euler/Problem 04/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(input("limit? "))
limit = int(raw_input("limit? "))

# fetchs the next number
for number in range(limit-1,10000,-1):
Expand Down
2 changes: 1 addition & 1 deletion Project Euler/Problem 04/sol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
arr.append(i*j)
arr.sort()

n=int(input())
n=int(raw_input())
for i in arr[::-1]:
if(i<n):
print(i)
Expand Down
2 changes: 1 addition & 1 deletion Project Euler/Problem 05/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'''
from __future__ import print_function

n = int(input())
n = int(raw_input())
i = 0
while 1:
i+=n*(n-1)
Expand Down
2 changes: 1 addition & 1 deletion Project Euler/Problem 05/sol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def gcd(x,y):
def lcm(x,y):
return (x*y)//gcd(x,y)

n = int(input())
n = int(raw_input())
g=1
for i in range(1,n+1):
g=lcm(g,i)
Expand Down
2 changes: 1 addition & 1 deletion Project Euler/Problem 06/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

suma = 0
sumb = 0
n = int(input())
n = int(raw_input())
for i in range(1,n+1):
suma += i**2
sumb += i
Expand Down
2 changes: 1 addition & 1 deletion Project Euler/Problem 06/sol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Find the difference between the sum of the squares of the first N natural numbers and the square of the sum.
'''
from __future__ import print_function
n = int(input())
n = int(raw_input())
suma = n*(n+1)/2
suma **= 2
sumb = n*(n+1)*(2*n+1)/6
Expand Down
2 changes: 1 addition & 1 deletion Project Euler/Problem 07/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def isprime(n):
if(n%i==0):
return False
return True
n = int(input())
n = int(raw_input())
i=0
j=1
while(i!=n and j<3):
Expand Down
2 changes: 1 addition & 1 deletion Project Euler/Problem 07/sol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def isprime(number):
if number%i==0:
return False
return True
n = int(input('Enter The N\'th Prime Number You Want To Get: ')) # Ask For The N'th Prime Number Wanted
n = int(raw_input('Enter The N\'th Prime Number You Want To Get: ')) # Ask For The N'th Prime Number Wanted
primes = []
num = 2
while len(primes) < n:
Expand Down
2 changes: 1 addition & 1 deletion Project Euler/Problem 08/sol1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
def main():
LargestProduct = -sys.maxsize-1
number=input().strip()
number=raw_input().strip()
for i in range(len(number)-13):
product=1
for j in range(13):
Expand Down
2 changes: 1 addition & 1 deletion Project Euler/Problem 09/sol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

product=-1
d=0
N = int(input())
N = int(raw_input())
for a in range(1,N//3):
"""Solving the two equations a**2+b**2=c**2 and a+b+c=N eliminating c """
b=(N*N-2*a*N)//(2*N-2*a)
Expand Down
4 changes: 2 additions & 2 deletions Project Euler/Problem 13/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
'''
from __future__ import print_function

n = int(input().strip())
n = int(raw_input().strip())

array = []
for i in range(n):
array.append(int(input().strip()))
array.append(int(raw_input().strip()))

print(str(sum(array))[:10])

2 changes: 1 addition & 1 deletion Project Euler/Problem 16/sol1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
power = int(input("Enter the power of 2: "))
power = int(raw_input("Enter the power of 2: "))
num = 2**power

string_num = str(num)
Expand Down
2 changes: 1 addition & 1 deletion Project Euler/Problem 20/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def split_and_add(number):
return sum_of_digits

# Taking the user input.
number = int(input("Enter the Number: "))
number = int(raw_input("Enter the Number: "))

# Assigning the factorial from the factorial function.
factorial = factorial(number)
Expand Down
4 changes: 2 additions & 2 deletions boolean_algebra/Quine_McCluskey/QuineMcCluskey.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def prime_implicant_chart(prime_implicants, binary):
return chart

def main():
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()]
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()]
binary = decimal_to_binary(no_of_variable, minterms)

prime_implicants = check(binary)
Expand Down
6 changes: 3 additions & 3 deletions ciphers/affine_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
SYMBOLS = """ !"#$%&'()*+,-./0123456789:;<=>?@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'
Expand Down
2 changes: 1 addition & 1 deletion ciphers/brute-force_caesar_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions ciphers/caesar_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion ciphers/rsa_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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'
Expand Down
4 changes: 2 additions & 2 deletions ciphers/simple_substitution_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
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)

Expand Down
6 changes: 3 additions & 3 deletions ciphers/transposition_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
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)
Expand Down
6 changes: 3 additions & 3 deletions ciphers/transposition_cipher_encrypt-decrypt_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
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()

Expand Down
6 changes: 3 additions & 3 deletions ciphers/vigenere_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
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'
Expand Down
12 changes: 6 additions & 6 deletions data_structures/Graph/BellmanFord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand All @@ -45,10 +45,10 @@ def BellmanFord(graph, V, E, src):

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)
12 changes: 6 additions & 6 deletions data_structures/Graph/Dijkstra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand All @@ -48,10 +48,10 @@ def Dijkstra(graph, V, src):

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)
Loading