Skip to content

Commit

Permalink
update deprecated files
Browse files Browse the repository at this point in the history
  • Loading branch information
vsc46128 vscuser committed Dec 4, 2023
1 parent 8577f58 commit 9f11040
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions intro-HPC/examples/Program-examples/01_Python/file3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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=')
Expand All @@ -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("[")
Expand All @@ -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.")

14 changes: 7 additions & 7 deletions intro-HPC/examples/Program-examples/01_Python/primes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand All @@ -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)



0 comments on commit 9f11040

Please sign in to comment.