From 07451a6ca4f284050ec9ff152561a3e691fc635d Mon Sep 17 00:00:00 2001 From: Parth Shandilya Date: Fri, 19 Oct 2018 13:28:21 +0530 Subject: [PATCH] Improved Code and removed warnings (#482) Improved Code and removed warnings --- Graphs/ArticulationPoints.py | 2 +- Graphs/MinimumSpanningTree_Prims.py | 4 ++-- Maths/FibonacciSequenceRecursion.py | 2 +- 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 +++ 14 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Graphs/ArticulationPoints.py b/Graphs/ArticulationPoints.py index 9965f5cb2..1173c4ea3 100644 --- a/Graphs/ArticulationPoints.py +++ b/Graphs/ArticulationPoints.py @@ -37,7 +37,7 @@ def computeAP(l): 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/Graphs/MinimumSpanningTree_Prims.py b/Graphs/MinimumSpanningTree_Prims.py index 7b1ad0e74..569e73e0a 100644 --- a/Graphs/MinimumSpanningTree_Prims.py +++ b/Graphs/MinimumSpanningTree_Prims.py @@ -101,8 +101,8 @@ def PrimsAlgorithm(l): 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()] diff --git a/Maths/FibonacciSequenceRecursion.py b/Maths/FibonacciSequenceRecursion.py index a97bb8b3f..b0b10fd07 100644 --- a/Maths/FibonacciSequenceRecursion.py +++ b/Maths/FibonacciSequenceRecursion.py @@ -9,7 +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("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: ") diff --git a/Neural_Network/bpnn.py b/Neural_Network/bpnn.py index ed5d4c8cb..0865e35f0 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 9bbd0c535..aa8dc7f76 100644 --- a/Project Euler/Problem 02/sol2.py +++ b/Project Euler/Problem 02/sol2.py @@ -9,4 +9,4 @@ T = int(input().strip()) 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 ed83e87d9..bb9f8ca9a 100644 --- a/Project Euler/Problem 03/sol1.py +++ b/Project Euler/Problem 03/sol1.py @@ -3,7 +3,7 @@ Problem: 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 02f6af83f..3992e2d4d 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 0f10a8600..98faf6135 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 d091f713b..9bd61559d 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 e66d02b6d..d0c2400eb 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 66d2b2ff0..cbc118467 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 db6415999..6387d4939 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 28cdff75a..d87792f45 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 e566f693f..6a06058fe 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.