mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
Modernize Python 2 code to get ready for Python 3
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
__author__ = "Tobias Carryer"
|
||||
|
||||
from time import time
|
||||
@ -31,4 +32,4 @@ if __name__ == "__main__":
|
||||
# Show the LCG in action.
|
||||
lcg = LinearCongruentialGenerator(1664525, 1013904223, 2<<31)
|
||||
while True :
|
||||
print lcg.next_number()
|
||||
print(lcg.next_number())
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
import collections, pprint, time, os
|
||||
|
||||
start_time = time.time()
|
||||
@ -25,4 +26,4 @@ with open('anagrams.txt', 'w') as file:
|
||||
file.write(pprint.pformat(all_anagrams))
|
||||
|
||||
total_time = round(time.time() - start_time, 2)
|
||||
print('Done [', total_time, 'seconds ]')
|
||||
print(('Done [', total_time, 'seconds ]'))
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
# https://en.wikipedia.org/wiki/Euclidean_algorithm
|
||||
|
||||
def euclidean_gcd(a, b):
|
||||
|
@ -13,6 +13,7 @@ The function called is_balanced takes as input a string S which is a sequence of
|
||||
returns true if S is nested and false otherwise.
|
||||
|
||||
'''
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
def is_balanced(S):
|
||||
@ -39,10 +40,10 @@ def main():
|
||||
S = input("Enter sequence of brackets: ")
|
||||
|
||||
if is_balanced(S):
|
||||
print(S, "is balanced")
|
||||
print((S, "is balanced"))
|
||||
|
||||
else:
|
||||
print(S, "is not balanced")
|
||||
print((S, "is not balanced"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
import string
|
||||
import random
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
def moveTower(height, fromPole, toPole, withPole):
|
||||
'''
|
||||
>>> moveTower(3, 'A', 'B', 'C')
|
||||
@ -15,7 +16,7 @@ def moveTower(height, fromPole, toPole, withPole):
|
||||
moveTower(height-1, withPole, toPole, fromPole)
|
||||
|
||||
def moveDisk(fp,tp):
|
||||
print('moving disk from', fp, 'to', tp)
|
||||
print(('moving disk from', fp, 'to', tp))
|
||||
|
||||
def main():
|
||||
height = int(input('Height of hanoi: '))
|
||||
|
@ -9,6 +9,7 @@ Given nums = [2, 7, 11, 15], target = 9,
|
||||
Because nums[0] + nums[1] = 2 + 7 = 9,
|
||||
return [0, 1].
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
def twoSum(nums, target):
|
||||
"""
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
import pprint, time
|
||||
|
||||
def getWordPattern(word):
|
||||
@ -32,7 +33,7 @@ def main():
|
||||
fo.write(pprint.pformat(allPatterns))
|
||||
|
||||
totalTime = round(time.time() - startTime, 2)
|
||||
print('Done! [', totalTime, 'seconds ]')
|
||||
print(('Done! [', totalTime, 'seconds ]'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Reference in New Issue
Block a user