Modernize Python 2 code to get ready for Python 3

This commit is contained in:
cclauss
2017-11-25 10:23:50 +01:00
parent a03b2eafc0
commit 4e06949072
95 changed files with 580 additions and 521 deletions

View File

@ -3,6 +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
import math
@ -20,12 +21,12 @@ def isprime(no):
max=0
n=int(input())
if(isprime(n)):
print n
print(n)
else:
while (n%2==0):
n=n/2
if(isprime(n)):
print n
print(n)
else:
n1 = int(math.sqrt(n))+1
for i in range(3,n1,2):
@ -35,4 +36,4 @@ else:
break
elif(isprime(i)):
max=i
print max
print(max)

View File

@ -3,6 +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
n=int(input())
prime=1
i=2
@ -13,4 +14,4 @@ while(i*i<=n):
i+=1
if(n>1):
prime=n
print prime
print(prime)