From 2ba459f3d31c3ba076125e4a6fcd476cc9a49f62 Mon Sep 17 00:00:00 2001 From: ParthS007 Date: Fri, 19 Oct 2018 12:58:17 +0530 Subject: [PATCH 1/3] Improved Code and removed warnings --- Graphs/ArticulationPoints.py | 2 +- Maths/FibonacciSequenceRecursion.py | 3 +-- Neural_Network/bpnn.py | 3 +++ Project Euler/Problem 02/sol2.py | 2 +- Project Euler/Problem 03/sol1.py | 2 +- data_structures/Graph/BreadthFirstSearch.py | 6 +++++- data_structures/Graph/DepthFirstSearch.py | 5 ++++- data_structures/Graph/Graph.py | 3 +++ data_structures/Heap/heap.py | 2 +- dynamic_programming/fastfibonacci.py | 3 +++ machine_learning/gradient_descent.py | 2 +- other/Fischer-Yates_Shuffle.py | 6 ++++-- other/sierpinski_triangle.py | 3 +++ 13 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Graphs/ArticulationPoints.py b/Graphs/ArticulationPoints.py index 9965f5cb23cd..1173c4ea373c 100644 --- a/Graphs/ArticulationPoints.py +++ b/Graphs/ArticulationPoints.py @@ -37,7 +37,7 @@ def dfs(root, at, parent, outEdgeCount): for x in range(len(isArt)): if isArt[x] == True: - print(x, end=" ") + print(x) # Adjacency list of graph l = {0:[1,2], 1:[0,2], 2:[0,1,3,5], 3:[2,4], 4:[3], 5:[2,6,8], 6:[5,7], 7:[6,8], 8:[5,7]} diff --git a/Maths/FibonacciSequenceRecursion.py b/Maths/FibonacciSequenceRecursion.py index a97bb8b3f124..104e88bd6dc4 100644 --- a/Maths/FibonacciSequenceRecursion.py +++ b/Maths/FibonacciSequenceRecursion.py @@ -9,8 +9,7 @@ def isPositiveInteger(limit): def main(): limit = int(input("How many terms to include in fibonacci series: ")) if isPositiveInteger(limit): - print(f"The first {limit} terms of the fibonacci series are as follows:") - print([recur_fibo(n) for n in range(limit)]) + print("The first {limit} terms of the fibonacci series are as follows:".format([recur_fibo(n) for n in range(limit)])) else: print("Please enter a positive integer: ") diff --git a/Neural_Network/bpnn.py b/Neural_Network/bpnn.py index ed5d4c8cbf79..0865e35f0b5c 100644 --- a/Neural_Network/bpnn.py +++ b/Neural_Network/bpnn.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# encoding=utf8 + ''' A Framework of Back Propagation Neural Network(BP) model diff --git a/Project Euler/Problem 02/sol2.py b/Project Euler/Problem 02/sol2.py index 9bbd0c535d63..aa8dc7f76f3b 100644 --- a/Project Euler/Problem 02/sol2.py +++ b/Project Euler/Problem 02/sol2.py @@ -9,4 +9,4 @@ def fib(n): ls = [] for _ in range(T): fib(int(input().strip())) -print(*ls, sep = '\n') +print(ls, sep = '\n') diff --git a/Project Euler/Problem 03/sol1.py b/Project Euler/Problem 03/sol1.py index ed83e87d9a5b..bb9f8ca9ad12 100644 --- a/Project Euler/Problem 03/sol1.py +++ b/Project Euler/Problem 03/sol1.py @@ -3,7 +3,7 @@ The prime factors of 13195 are 5,7,13 and 29. What is the largest prime factor of a given number N? e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17. ''' -from __future__ import print_function +from __future__ import print_function, division import math diff --git a/data_structures/Graph/BreadthFirstSearch.py b/data_structures/Graph/BreadthFirstSearch.py index 02f6af83ff66..3992e2d4d892 100644 --- a/data_structures/Graph/BreadthFirstSearch.py +++ b/data_structures/Graph/BreadthFirstSearch.py @@ -1,4 +1,8 @@ -# Author: OMKAR PATHAK +#!/usr/bin/python +# encoding=utf8 + +""" Author: OMKAR PATHAK """ + from __future__ import print_function diff --git a/data_structures/Graph/DepthFirstSearch.py b/data_structures/Graph/DepthFirstSearch.py index 0f10a8600099..98faf61354f9 100644 --- a/data_structures/Graph/DepthFirstSearch.py +++ b/data_structures/Graph/DepthFirstSearch.py @@ -1,4 +1,7 @@ -# Author: OMKAR PATHAK +#!/usr/bin/python +# encoding=utf8 + +""" Author: OMKAR PATHAK """ from __future__ import print_function diff --git a/data_structures/Graph/Graph.py b/data_structures/Graph/Graph.py index d091f713b8d9..9bd61559dcbf 100644 --- a/data_structures/Graph/Graph.py +++ b/data_structures/Graph/Graph.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# encoding=utf8 + from __future__ import print_function # Author: OMKAR PATHAK diff --git a/data_structures/Heap/heap.py b/data_structures/Heap/heap.py index e66d02b6d99f..d0c2400eb6b5 100644 --- a/data_structures/Heap/heap.py +++ b/data_structures/Heap/heap.py @@ -1,6 +1,6 @@ #!/usr/bin/python -from __future__ import print_function +from __future__ import print_function, division try: raw_input # Python 2 diff --git a/dynamic_programming/fastfibonacci.py b/dynamic_programming/fastfibonacci.py index 66d2b2ff0a54..cbc118467b3c 100644 --- a/dynamic_programming/fastfibonacci.py +++ b/dynamic_programming/fastfibonacci.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# encoding=utf8 + """ This program calculates the nth Fibonacci number in O(log(n)). It's possible to calculate F(1000000) in less than a second. diff --git a/machine_learning/gradient_descent.py b/machine_learning/gradient_descent.py index db6415999bd7..6387d4939205 100644 --- a/machine_learning/gradient_descent.py +++ b/machine_learning/gradient_descent.py @@ -1,7 +1,7 @@ """ Implementation of gradient descent algorithm for minimizing cost of a linear hypothesis function. """ -from __future__ import print_function +from __future__ import print_function, division import numpy # List of input, output pairs diff --git a/other/Fischer-Yates_Shuffle.py b/other/Fischer-Yates_Shuffle.py index 28cdff75ab85..d87792f45558 100644 --- a/other/Fischer-Yates_Shuffle.py +++ b/other/Fischer-Yates_Shuffle.py @@ -1,8 +1,10 @@ -''' +#!/usr/bin/python +# encoding=utf8 +""" The Fisher–Yates shuffle is an algorithm for generating a random permutation of a finite sequence. For more details visit wikipedia/Fischer-Yates-Shuffle. -''' +""" import random def FYshuffle(LIST): diff --git a/other/sierpinski_triangle.py b/other/sierpinski_triangle.py index e566f693f63b..6a06058fe03e 100644 --- a/other/sierpinski_triangle.py +++ b/other/sierpinski_triangle.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# encoding=utf8 + '''Author Anurag Kumar | anuragkumarak95@gmail.com | git/anuragkumarak95 Simple example of Fractal generation using recursive function. From 4b9d504cfe8644f148f8f457d96ef38a1aa37ba5 Mon Sep 17 00:00:00 2001 From: ParthS007 Date: Fri, 19 Oct 2018 13:11:14 +0530 Subject: [PATCH 2/3] Improved Code and removed warnings --- Graphs/MinimumSpanningTree_Prims.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Graphs/MinimumSpanningTree_Prims.py b/Graphs/MinimumSpanningTree_Prims.py index 7b1ad0e743f7..569e73e0ab7b 100644 --- a/Graphs/MinimumSpanningTree_Prims.py +++ b/Graphs/MinimumSpanningTree_Prims.py @@ -101,8 +101,8 @@ def deleteMinimum(heap, positions): return TreeEdges # < --------- Prims Algorithm --------- > -n = int(input("Enter number of vertices: ")) -e = int(input("Enter number of edges: ")) +n = int(raw_input("Enter number of vertices: ")) +e = int(raw_input("Enter number of edges: ")) adjlist = defaultdict(list) for x in range(e): l = [int(x) for x in input().split()] From 42468dfb39bf360a9bbb55136abc6f2391c4b1f6 Mon Sep 17 00:00:00 2001 From: ParthS007 Date: Fri, 19 Oct 2018 13:20:07 +0530 Subject: [PATCH 3/3] Improved Code and removed warnings --- Maths/FibonacciSequenceRecursion.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Maths/FibonacciSequenceRecursion.py b/Maths/FibonacciSequenceRecursion.py index 104e88bd6dc4..b0b10fd07262 100644 --- a/Maths/FibonacciSequenceRecursion.py +++ b/Maths/FibonacciSequenceRecursion.py @@ -9,7 +9,8 @@ def isPositiveInteger(limit): def main(): limit = int(input("How many terms to include in fibonacci series: ")) if isPositiveInteger(limit): - print("The first {limit} terms of the fibonacci series are as follows:".format([recur_fibo(n) for n in range(limit)])) + print("The first {limit} terms of the fibonacci series are as follows:") + print([recur_fibo(n) for n in range(limit)]) else: print("Please enter a positive integer: ")