Skip to content

Commit ea2ddaa

Browse files
committed
all valid python 3
1 parent b566055 commit ea2ddaa

37 files changed

+76
-1436
lines changed

boolean_algebra/quine_mc_cluskey.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def prime_implicant_chart(prime_implicants, binary):
9999
return chart
100100

101101
def main():
102-
no_of_variable = int(raw_input("Enter the no. of variables\n"))
103-
minterms = [int(x) for x in raw_input("Enter the decimal representation of Minterms 'Spaces Seprated'\n").split()]
102+
no_of_variable = int(input("Enter the no. of variables\n"))
103+
minterms = [int(x) for x in input("Enter the decimal representation of Minterms 'Spaces Seprated'\n").split()]
104104
binary = decimal_to_binary(no_of_variable, minterms)
105105

106106
prime_implicants = check(binary)
@@ -113,4 +113,4 @@ def main():
113113
print(essential_prime_implicants)
114114

115115
if __name__ == '__main__':
116-
main()
116+
main()

ciphers/affine_cipher.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
SYMBOLS = """ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"""
55

66
def main():
7-
message = raw_input('Enter message: ')
8-
key = int(raw_input('Enter key [2000 - 9000]: '))
9-
mode = raw_input('Encrypt/Decrypt [E/D]: ')
7+
message = input('Enter message: ')
8+
key = int(input('Enter key [2000 - 9000]: '))
9+
mode = input('Encrypt/Decrypt [E/D]: ')
1010

1111
if mode.lower().startswith('e'):
1212
mode = 'encrypt'

ciphers/brute_force_caesar_cipher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def decrypt(message):
4444
print("Decryption using Key #%s: %s" % (key, translated))
4545

4646
def main():
47-
message = raw_input("Encrypted message: ")
47+
message = input("Encrypted message: ")
4848
message = message.upper()
4949
decrypt(message)
5050

ciphers/caesar_cipher.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,25 @@ def main():
4040
print("3.BruteForce")
4141
print("4.Quit")
4242
while True:
43-
choice = raw_input("What would you like to do?: ")
43+
choice = input("What would you like to do?: ")
4444
if choice not in ['1', '2', '3', '4']:
4545
print ("Invalid choice")
4646
elif choice == '1':
47-
strng = raw_input("Please enter the string to be ecrypted: ")
47+
strng = input("Please enter the string to be ecrypted: ")
4848
while True:
4949
key = int(input("Please enter off-set between 1-94: "))
5050
if key in range(1, 95):
5151
print (encrypt(strng, key))
5252
main()
5353
elif choice == '2':
54-
strng = raw_input("Please enter the string to be decrypted: ")
54+
strng = input("Please enter the string to be decrypted: ")
5555
while True:
5656
key = raw_int(input("Please enter off-set between 1-94: "))
5757
if key > 0 and key <= 94:
5858
print(decrypt(strng, key))
5959
main()
6060
elif choice == '3':
61-
strng = raw_input("Please enter the string to be decrypted: ")
61+
strng = input("Please enter the string to be decrypted: ")
6262
brute_force(strng)
6363
main()
6464
elif choice == '4':

ciphers/rsa_cipher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def main():
88
filename = 'encrypted_file.txt'
9-
response = raw_input('Encrypte\Decrypt [e\d]: ')
9+
response = input('Encrypte\Decrypt [e\d]: ')
1010

1111
if response.lower().startswith('e'):
1212
mode = 'encrypt'

ciphers/simple_substitution_cipher.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
55

66
def main():
7-
message = raw_input('Enter message: ')
7+
message = input('Enter message: ')
88
key = 'LFWOAYUISVKMNXPBDCRJTQEGHZ'
9-
resp = raw_input('Encrypt/Decrypt [e/d]: ')
9+
resp = input('Encrypt/Decrypt [e/d]: ')
1010

1111
checkValidKey(key)
1212

ciphers/transposition_cipher.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import math
33

44
def main():
5-
message = raw_input('Enter message: ')
6-
key = int(raw_input('Enter key [2-%s]: ' % (len(message) - 1)))
7-
mode = raw_input('Encryption/Decryption [e/d]: ')
5+
message = input('Enter message: ')
6+
key = int(input('Enter key [2-%s]: ' % (len(message) - 1)))
7+
mode = input('Encryption/Decryption [e/d]: ')
88

99
if mode.lower().startswith('e'):
1010
text = encryptMessage(key, message)

ciphers/transposition_cipher_encrypt_decrypt_file.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
def main():
66
inputFile = 'Prehistoric Men.txt'
77
outputFile = 'Output.txt'
8-
key = int(raw_input('Enter key: '))
9-
mode = raw_input('Encrypt/Decrypt [e/d]: ')
8+
key = int(input('Enter key: '))
9+
mode = input('Encrypt/Decrypt [e/d]: ')
1010

1111
if not os.path.exists(inputFile):
1212
print('File %s does not exist. Quitting...' % inputFile)
1313
sys.exit()
1414
if os.path.exists(outputFile):
1515
print('Overwrite %s? [y/n]' % outputFile)
16-
response = raw_input('> ')
16+
response = input('> ')
1717
if not response.lower().startswith('y'):
1818
sys.exit()
1919

ciphers/vigenere_cipher.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
33

44
def main():
5-
message = raw_input('Enter message: ')
6-
key = raw_input('Enter key [alphanumeric]: ')
7-
mode = raw_input('Encrypt/Decrypt [e/d]: ')
5+
message = input('Enter message: ')
6+
key = input('Enter key [alphanumeric]: ')
7+
mode = input('Encrypt/Decrypt [e/d]: ')
88

99
if mode.lower().startswith('e'):
1010
mode = 'encrypt'

data_structures/graph/bellman_ford.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def BellmanFord(graph, V, E, src):
3535

3636

3737
#MAIN
38-
V = int(raw_input("Enter number of vertices: "))
39-
E = int(raw_input("Enter number of edges: "))
38+
V = int(input("Enter number of vertices: "))
39+
E = int(input("Enter number of edges: "))
4040

4141
graph = [dict() for j in range(E)]
4242

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

4646
for i in range(E):
4747
print("\nEdge ",i+1)
48-
src = int(raw_input("Enter source:"))
49-
dst = int(raw_input("Enter destination:"))
50-
weight = float(raw_input("Enter weight:"))
48+
src = int(input("Enter source:"))
49+
dst = int(input("Enter destination:"))
50+
weight = float(input("Enter weight:"))
5151
graph[i] = {"src": src,"dst": dst, "weight": weight}
5252

53-
gsrc = int(raw_input("\nEnter shortest path source:"))
53+
gsrc = int(input("\nEnter shortest path source:"))
5454
BellmanFord(graph, V, E, gsrc)

data_structures/graph/dijkstra.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def Dijkstra(graph, V, src):
3838

3939

4040
#MAIN
41-
V = int(raw_input("Enter number of vertices: "))
42-
E = int(raw_input("Enter number of edges: "))
41+
V = int(input("Enter number of vertices: "))
42+
E = int(input("Enter number of edges: "))
4343

4444
graph = [[float('inf') for i in range(V)] for j in range(V)]
4545

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

4949
for i in range(E):
5050
print("\nEdge ",i+1)
51-
src = int(raw_input("Enter source:"))
52-
dst = int(raw_input("Enter destination:"))
53-
weight = float(raw_input("Enter weight:"))
51+
src = int(input("Enter source:"))
52+
dst = int(input("Enter destination:"))
53+
weight = float(input("Enter weight:"))
5454
graph[src][dst] = weight
5555

56-
gsrc = int(raw_input("\nEnter shortest path source:"))
56+
gsrc = int(input("\nEnter shortest path source:"))
5757
Dijkstra(graph, V, gsrc)

data_structures/graph/floyd_warshall.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def FloydWarshall(graph, V):
3030

3131

3232
#MAIN
33-
V = int(raw_input("Enter number of vertices: "))
34-
E = int(raw_input("Enter number of edges: "))
33+
V = int(input("Enter number of vertices: "))
34+
E = int(input("Enter number of edges: "))
3535

3636
graph = [[float('inf') for i in range(V)] for j in range(V)]
3737

@@ -40,9 +40,9 @@ def FloydWarshall(graph, V):
4040

4141
for i in range(E):
4242
print("\nEdge ",i+1)
43-
src = int(raw_input("Enter source:"))
44-
dst = int(raw_input("Enter destination:"))
45-
weight = float(raw_input("Enter weight:"))
43+
src = int(input("Enter source:"))
44+
dst = int(input("Enter destination:"))
45+
weight = float(input("Enter weight:"))
4646
graph[src][dst] = weight
4747

4848
FloydWarshall(graph, V)

graphs/minimum_spanning_tree_kruskal.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from __future__ import print_function
2-
num_nodes, num_edges = list(map(int,raw_input().split()))
2+
num_nodes, num_edges = list(map(int,input().split()))
33

44
edges = []
55

66
for i in range(num_edges):
7-
node1, node2, cost = list(map(int,raw_input().split()))
7+
node1, node2, cost = list(map(int,input().split()))
88
edges.append((i,node1,node2,cost))
99

1010
edges = sorted(edges, key=lambda edge: edge[3])

graphs/minimum_spanning_tree_prims.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def deleteMinimum(heap, positions):
101101
return TreeEdges
102102

103103
# < --------- Prims Algorithm --------- >
104-
n = int(raw_input("Enter number of vertices: "))
105-
e = int(raw_input("Enter number of edges: "))
104+
n = int(input("Enter number of vertices: "))
105+
e = int(input("Enter number of edges: "))
106106
adjlist = defaultdict(list)
107107
for x in range(e):
108108
l = [int(x) for x in input().split()]

graphs/scc_kosaraju.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from __future__ import print_function
22
# n - no of nodes, m - no of edges
3-
n, m = list(map(int,raw_input().split()))
3+
n, m = list(map(int,input().split()))
44

55
g = [[] for i in range(n)] #graph
66
r = [[] for i in range(n)] #reversed graph
77
# input graph data (edges)
88
for i in range(m):
9-
u, v = list(map(int,raw_input().split()))
9+
u, v = list(map(int,input().split()))
1010
g[u].append(v)
1111
r[v].append(u)
1212

machine_learning/perceptron.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,5 @@ def sign(self, u):
120120
while True:
121121
sample = []
122122
for i in range(3):
123-
sample.insert(i, float(raw_input('value: ')))
124-
network.sort(sample)
123+
sample.insert(i, float(input('value: ')))
124+
network.sort(sample)

maths/sieve_of_eratosthenes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import math
2-
n = int(raw_input("Enter n: "))
2+
n = int(input("Enter n: "))
33

44
def sieve(n):
55
l = [True] * (n+1)
@@ -21,4 +21,4 @@ def sieve(n):
2121
return prime
2222

2323
print(sieve(n))
24-
24+

neural_network/perceptron.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,5 @@ def sign(self, u):
120120
while True:
121121
sample = []
122122
for i in range(3):
123-
sample.insert(i, float(raw_input('value: ')))
123+
sample.insert(i, float(input('value: ')))
124124
network.sort(sample)

other/nested_brackets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def is_balanced(S):
3737

3838
def main():
3939

40-
S = raw_input("Enter sequence of brackets: ")
40+
S = input("Enter sequence of brackets: ")
4141

4242
if is_balanced(S):
4343
print((S, "is balanced"))

other/tower_of_hanoi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def moveDisk(fp,tp):
1919
print(('moving disk from', fp, 'to', tp))
2020

2121
def main():
22-
height = int(raw_input('Height of hanoi: '))
22+
height = int(input('Height of hanoi: '))
2323
moveTower(height, 'A', 'B', 'C')
2424

2525
if __name__ == '__main__':

project_euler/problem_02/sol3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
e.g. for n=10, we have {2,8}, sum is 10.
88
'''
99
"""Python 3"""
10-
n = int(raw_input())
10+
n = int(input())
1111
a=0
1212
b=2
1313
count=0

project_euler/problem_03/sol1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def isprime(no):
1919
return True
2020

2121
maxNumber = 0
22-
n=int(raw_input())
22+
n=int(input())
2323
if(isprime(n)):
2424
print(n)
2525
else:

project_euler/problem_03/sol2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17.
55
'''
66
from __future__ import print_function
7-
n=int(raw_input())
7+
n=int(input())
88
prime=1
99
i=2
1010
while(i*i<=n):

project_euler/problem_04/sol1.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Find the largest palindrome made from the product of two 3-digit numbers which is less than N.
55
'''
66
from __future__ import print_function
7-
limit = int(raw_input("limit? "))
7+
limit = int(input("limit? "))
88

99
# fetchs the next number
1010
for number in range(limit-1,10000,-1):
@@ -26,4 +26,4 @@
2626
print(number)
2727
exit(0)
2828

29-
divisor -=1
29+
divisor -=1

project_euler/problem_04/sol2.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
arr.append(i*j)
1313
arr.sort()
1414

15-
n=int(raw_input())
15+
n=int(input())
1616
for i in arr[::-1]:
1717
if(i<n):
1818
print(i)
19-
exit(0)
19+
exit(0)

project_euler/problem_05/sol1.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
'''
66
from __future__ import print_function
77

8-
n = int(raw_input())
8+
n = int(input())
99
i = 0
1010
while 1:
1111
i+=n*(n-1)
@@ -18,4 +18,4 @@
1818
if(i==0):
1919
i=1
2020
print(i)
21-
break
21+
break

project_euler/problem_05/sol2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def gcd(x,y):
1313
def lcm(x,y):
1414
return (x*y)//gcd(x,y)
1515

16-
n = int(raw_input())
16+
n = int(input())
1717
g=1
1818
for i in range(1,n+1):
1919
g=lcm(g,i)

project_euler/problem_06/sol1.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
suma = 0
1414
sumb = 0
15-
n = int(raw_input())
15+
n = int(input())
1616
for i in range(1,n+1):
1717
suma += i**2
1818
sumb += i
1919
sum = sumb**2 - suma
20-
print(sum)
20+
print(sum)

0 commit comments

Comments
 (0)