diff --git a/intro-HPC/examples/Program-examples/01_Python/file3.py b/intro-HPC/examples/Program-examples/01_Python/file3.py index e56ecaafd99..c07ae5355aa 100755 --- a/intro-HPC/examples/Program-examples/01_Python/file3.py +++ b/intro-HPC/examples/Program-examples/01_Python/file3.py @@ -13,8 +13,8 @@ # def primes(top): result = [] - for n in range(2, top): - for x in range(2, n/2+1): + for n in range(2, top+1): + for x in range(2, n): if n % x == 0: break else: @@ -33,11 +33,11 @@ def primes(top): # scratch_dir = os.environ.get('VSC_SCRATCH') filename_p1 = scratch_dir + "/primes_1.txt" -print "Output File: ", filename_p1 +print("Output File: ", filename_p1) f_out = open(filename_p1, 'w+') for i in range(1, 30000): # We take a random integer between 1 and 2000 - top = random.randrange(2000) + top = random.randrange(2,2000) # and we calculate all primes up to that limit l = primes(top) f_out.write('TOP=') @@ -60,8 +60,8 @@ def primes(top): filename_p2 = scratch_dir + "/primes_2.txt" f_in=open(filename_p1, "r") f_out=open(filename_p2, "w") -print "Input File: ", filename_p1 -print "Output File: ", filename_p2 +print("Input File: ", filename_p1) +print("Output File: ", filename_p2) in_lines=f_in.readlines() #reads it line by line for line in in_lines: delim = line.find("[") @@ -82,5 +82,5 @@ def primes(top): end_time = int(time.time()) duration = end_time - start_time -print "Duration = " + str(duration) + " seconds." +print("Duration = " + str(duration) + " seconds.") diff --git a/intro-HPC/examples/Program-examples/01_Python/primes.py b/intro-HPC/examples/Program-examples/01_Python/primes.py index 37e85302ad7..20b93fbf3c5 100755 --- a/intro-HPC/examples/Program-examples/01_Python/primes.py +++ b/intro-HPC/examples/Program-examples/01_Python/primes.py @@ -18,7 +18,7 @@ def ask_int(prompt, retries=3): if num > 1: return num else: - print "Please enter an integer which is bigger as one." + print('Please enter an integer which is bigger as one.') retries = retries - 1 if retries <= 0: print('Too many attempts, try again later.') @@ -27,23 +27,23 @@ def ask_int(prompt, retries=3): # # PRIMES # -print "This program calculates all primes between 1 and your upper limit." +print('This program calculates all primes between 1 and your upper limit.') num = ask_int('Enter your upper limit (>1): ') start_time = print_time("Start Time: ") -print "[Prime#1] = 1" +print('[Prime#1] = 1') ctr = 1 -for n in range(2, int(num)): - for x in range(2, n/2+1): +for n in range(2, int(num)+1): + for x in range(2, n): if n % x == 0: break else: # loop fell through without finding a factor ctr += 1 - print "[Prime#%i] = %i" % (ctr,n) + print('[Prime#%i] = %i' % (ctr,n)) end_time = print_time("End Time: ") duration = end_time - start_time s = "Duration: " + str(duration) + " seconds." -print s +print(s)