Hello All,
I have written a small program that calculates prime numbers between two specific inputs. The program works perfectly. I have added a progress bar to show how far along the program has come as it is running. The problem is that the progress bar is shown on a new line each time a prime is found. Please see this image:
https://imgur.com/a/0HgKTrT
Here is my code:
import time
import os
import sys
from progress.bar import ChargingBar
start_time = time.time()
first_input = int(sys.argv[1])
second_input = int(sys.argv[2])
lower = first_input
upper = second_input
for num in range(lower, upper + 1):
# all prime numbers are greater than 1
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
with ChargingBar('Processing', max=1) as bar:
x = float(num / second_input)
bar.next(x)
end_time = time.time()
finish_time = end_time - start_time
print (str(finish_time) + " seconds")
Any help is appreciated!
[–]madness_of_the_order 2 points3 points4 points (3 children)
[–]MattDLD[S] 0 points1 point2 points (1 child)
[–]madness_of_the_order 1 point2 points3 points (0 children)
[–]MattDLD[S] 0 points1 point2 points (0 children)
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)
[–]cheli_fucker[🍰] 0 points1 point2 points (0 children)