print() is a function just like every other function (#1101)

* print() is a function just like every other function
This commit is contained in:
Christian Clauss 2019-08-06 12:14:23 +02:00 committed by Harshil
parent 6654e1ec7d
commit 89acf5d017
13 changed files with 133 additions and 133 deletions

View File

@ -20,13 +20,13 @@ def NewtonRaphson(func, a):
if __name__ == '__main__':
# Find root of trigonometric function
# Find value of pi
print ('sin(x) = 0', NewtonRaphson('sin(x)', 2))
print('sin(x) = 0', NewtonRaphson('sin(x)', 2))
# Find root of polynomial
print ('x**2 - 5*x +2 = 0', NewtonRaphson('x**2 - 5*x +2', 0.4))
print('x**2 - 5*x +2 = 0', NewtonRaphson('x**2 - 5*x +2', 0.4))
# Find Square Root of 5
print ('x**2 - 5 = 0', NewtonRaphson('x**2 - 5', 0.1))
print('x**2 - 5 = 0', NewtonRaphson('x**2 - 5', 0.1))
# Exponential Roots
print ('exp(x) - 1 = 0', NewtonRaphson('exp(x) - 1', 0))
print('exp(x) - 1 = 0', NewtonRaphson('exp(x) - 1', 0))

View File

@ -41,12 +41,12 @@ def main():
print("4.Quit")
choice = input("What would you like to do?: ")
if choice not in ['1', '2', '3', '4']:
print ("Invalid choice, please enter a valid choice")
print("Invalid choice, please enter a valid choice")
elif choice == '1':
strng = input("Please enter the string to be encrypted: ")
key = int(input("Please enter off-set between 1-94: "))
if key in range(1, 95):
print (encrypt(strng.lower(), key))
print(encrypt(strng.lower(), key))
elif choice == '2':
strng = input("Please enter the string to be decrypted: ")
key = int(input("Please enter off-set between 1-94: "))
@ -57,7 +57,7 @@ def main():
brute_force(strng)
main()
elif choice == '4':
print ("Goodbye.")
print("Goodbye.")
break

View File

@ -71,11 +71,11 @@ def decrypt(message):
def main():
message = "Morse code here"
result = encrypt(message.upper())
print (result)
print(result)
message = result
result = decrypt(message)
print (result)
print(result)
if __name__ == '__main__':

View File

@ -83,4 +83,4 @@ if __name__ == '__main__':
msg = "DEFEND THE EAST WALL OF THE CASTLE."
encrypted = encryptMessage(msg,"EPSDUCVWYM.ZLKXNBTFGORIJHAQ")
decrypted = decryptMessage(encrypted, "EPSDUCVWYM.ZLKXNBTFGORIJHAQ")
print ("Encrypted: {}\nDecrypted: {}".format(encrypted, decrypted))
print("Encrypted: {}\nDecrypted: {}".format(encrypted, decrypted))

View File

@ -188,22 +188,22 @@ class XORCipher(object):
# key = 67
# # test enrcypt
# print crypt.encrypt("hallo welt",key)
# print(crypt.encrypt("hallo welt",key))
# # test decrypt
# print crypt.decrypt(crypt.encrypt("hallo welt",key), key)
# print(crypt.decrypt(crypt.encrypt("hallo welt",key), key))
# # test encrypt_string
# print crypt.encrypt_string("hallo welt",key)
# print(crypt.encrypt_string("hallo welt",key))
# # test decrypt_string
# print crypt.decrypt_string(crypt.encrypt_string("hallo welt",key),key)
# print(crypt.decrypt_string(crypt.encrypt_string("hallo welt",key),key))
# if (crypt.encrypt_file("test.txt",key)):
# print "encrypt successful"
# print("encrypt successful")
# else:
# print "encrypt unsuccessful"
# print("encrypt unsuccessful")
# if (crypt.decrypt_file("encrypt.out",key)):
# print "decrypt successful"
# print("decrypt successful")
# else:
# print "decrypt unsuccessful"
# print("decrypt unsuccessful")

View File

@ -21,9 +21,9 @@ if __name__ == '__main__':
f = FenwickTree(100)
f.update(1,20)
f.update(4,4)
print (f.query(1))
print (f.query(3))
print (f.query(4))
print(f.query(1))
print(f.query(3))
print(f.query(4))
f.update(2,-5)
print (f.query(1))
print (f.query(3))
print(f.query(1))
print(f.query(3))

View File

@ -74,7 +74,7 @@ class SegmentTree:
showList = []
for i in range(1,N+1):
showList += [self.query(1, 1, self.N, i, i)]
print (showList)
print(showList)
if __name__ == '__main__':
@ -82,10 +82,10 @@ if __name__ == '__main__':
N = 15
segt = SegmentTree(N)
segt.build(1,1,N,A)
print (segt.query(1,1,N,4,6))
print (segt.query(1,1,N,7,11))
print (segt.query(1,1,N,7,12))
print(segt.query(1,1,N,4,6))
print(segt.query(1,1,N,7,11))
print(segt.query(1,1,N,7,12))
segt.update(1,1,N,1,3,111)
print (segt.query(1,1,N,1,15))
print(segt.query(1,1,N,1,15))
segt.update(1,1,N,7,8,235)
segt.showData()

View File

@ -55,17 +55,17 @@ class SegmentTree:
showList = []
for i in range(1,N+1):
showList += [self.query(i, i)]
print (showList)
print(showList)
if __name__ == '__main__':
A = [1,2,-4,7,3,-5,6,11,-20,9,14,15,5,2,-8]
N = 15
segt = SegmentTree(A)
print (segt.query(4, 6))
print (segt.query(7, 11))
print (segt.query(7, 12))
print(segt.query(4, 6))
print(segt.query(7, 11))
print(segt.query(7, 12))
segt.update(1,3,111)
print (segt.query(1, 15))
print(segt.query(1, 15))
segt.update(7,8,235)
segt.showData()

View File

@ -13,28 +13,28 @@ de = collections.deque([1, 2, 3,])
de.extend([4,5,6])
# printing modified deque
print ("The deque after extending deque at end is : ")
print (de)
print("The deque after extending deque at end is : ")
print(de)
# using extendleft() to add numbers to left end
# adds 7,8,9 to right end
de.extendleft([7,8,9])
# printing modified deque
print ("The deque after extending deque at beginning is : ")
print (de)
print("The deque after extending deque at beginning is : ")
print(de)
# using rotate() to rotate the deque
# rotates by 3 to left
de.rotate(-3)
# printing modified deque
print ("The deque after rotating deque is : ")
print (de)
print("The deque after rotating deque is : ")
print(de)
# using reverse() to reverse the deque
de.reverse()
# printing modified deque
print ("The deque after reversing deque is : ")
print (de)
print("The deque after reversing deque is : ")
print(de)

View File

@ -38,7 +38,7 @@ def calculateSpan(price, S):
# A utility function to print elements of array
def printArray(arr, n):
for i in range(0,n):
print (arr[i],end =" ")
print(arr[i],end =" ")
# Driver program to test above function

View File

@ -65,8 +65,8 @@ def logistic_reg(
return weights
if iterations == max_iterations:
print ('Maximum iterations exceeded!')
print ('Minimal cost function J=', J)
print('Maximum iterations exceeded!')
print('Minimal cost function J=', J)
converged = True
return theta
@ -79,7 +79,7 @@ if __name__ == '__main__':
alpha = 0.1
theta = logistic_reg(alpha,X,y,max_iterations=70000,num_steps=30000)
print (theta)
print(theta)
def predict_prob(X):

View File

@ -12,7 +12,7 @@ def QuadraticEquation(a,b,c):
if Delta >= 0:
Solution1 = (-b + math.sqrt(Delta))/(2*a)
Solution2 = (-b - math.sqrt(Delta))/(2*a)
print ("The equation solutions are: ", Solution1," and ", Solution2)
print("The equation solutions are: ", Solution1," and ", Solution2)
else:
"""
Treats cases of Complexes Solutions(i = imaginary unit)

View File

@ -17,6 +17,6 @@ def FYshuffle(LIST):
if __name__ == '__main__':
integers = [0,1,2,3,4,5,6,7]
strings = ['python', 'says', 'hello', '!']
print ('Fisher-Yates Shuffle:')
print ('List',integers, strings)
print ('FY Shuffle',FYshuffle(integers), FYshuffle(strings))
print('Fisher-Yates Shuffle:')
print('List',integers, strings)
print('FY Shuffle',FYshuffle(integers), FYshuffle(strings))