Hackerszone
Welcome Guest,
learn to hack easily with tutorials, python, notepad hacks and more!
Join today, fast and free!

Are you new to hacking? Learn the basics in computer configuration, hacking tools, and hacker terminology all found here on this forum!

Join today!!

Join the forum, it's quick and easy

Hackerszone
Welcome Guest,
learn to hack easily with tutorials, python, notepad hacks and more!
Join today, fast and free!

Are you new to hacking? Learn the basics in computer configuration, hacking tools, and hacker terminology all found here on this forum!

Join today!!
Hackerszone
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
 
 

Display results as :
 

 


Rechercher Advanced Search

HZ Tracker
Hacking Widget Visitor Details
Latest topics
»  How to study to understand and apply RPA?
[Python] Prime Numbers Script EmptyTue Feb 02, 2021 7:12 am by manas41

» SQL injection and Quote escaping
[Python] Prime Numbers Script EmptySun Jun 28, 2015 11:42 am by ADS1

» [TUT] Chmod: Files & Permissions [TUT]
[Python] Prime Numbers Script EmptyThu Jun 04, 2015 12:45 pm by Guest

» Reaver pixiewps
[Python] Prime Numbers Script EmptyThu Jun 04, 2015 12:23 pm by voidfletcher

» How To Crash Someone's Skype in 10 SECONDS
[Python] Prime Numbers Script EmptyThu Jun 04, 2015 12:20 pm by voidfletcher

» Internet Security & IP Security (IPSec)
[Python] Prime Numbers Script EmptyMon May 18, 2015 9:00 pm by voidfletcher

» [Python] Infinite / Definite File Generator
[Python] Prime Numbers Script EmptyMon May 18, 2015 8:58 pm by ADS1

» [C#] String Case-Inversion
[Python] Prime Numbers Script EmptyMon May 18, 2015 8:57 pm by ADS1

» Rekall Memory Forensic Framework
[Python] Prime Numbers Script EmptySat May 16, 2015 8:55 pm by ADS1

Who is online?
In total there are 5 users online :: 0 Registered, 0 Hidden and 5 Guests :: 1 Bot

None

[ View the whole list ]


Most users ever online was 38 on Sun Mar 19, 2023 10:07 pm

[Python] Prime Numbers Script

Go down

[Python] Prime Numbers Script Empty [Python] Prime Numbers Script

Post by cloud9 Sun Jan 04, 2015 10:46 am

Hello Smile

I was starting to code again in python so to practice my skills I was solving some of the problems of SPOJ.
I'd like to hear your opinion about this code. I know python has some libraries to do this faster and easier, but the point was to practice, so I just used built-in stuff.

What this piece of code does is asking user for t lines. Each t line has m and n (separated by space). Then it outputs the prime numbers between m and n. There's some limitations on m and n tho'.

Any kind of suggestions, tips, recommendations are welcome!
Thank you in advance.

Code:

[You must be registered and logged in to see this link.] for t
while True:
t = int(raw_input("Input number of lines: "))
if t > 10 or t <= 0:
print "This value can't be greater than ten, equal or less than zero!"
else:
break

[You must be registered and logged in to see this link.] for m and n
lines = []
count = 0
while count < t:
for i in range(1, (t + 1)):
line = raw_input("Input m y n: ")
line = line.split()
line = [int(i) for i in line]
m, n = line[0], line[1]
if (m >= 1) and (n <= 1000000000):
if (n - m <= 100000) and (m < n):
lines.append(line)
count += 1
else:
print "Invalid values"
else:
print "Invalid values"

[You must be registered and logged in to see this link.] lists to iterate next
num_ran = []
for i in lines:
r = range(i[0], (i[1] + 1))
num_ran.append(r)

[You must be registered and logged in to see this link.] the prime numbers
for i in range(0, len(num_ran)):
for j in num_ran[i][:]:
if j == 1 or j == 4:
num_ran[i].remove(j)
for k in range(2, (j/2)):
if j%k == 0:
num_ran[i].remove(j)
break

[You must be registered and logged in to see this link.] a little bit of decent output
c = 0
for i in lines:
print "Prime numbers between %s and %s are:"%(i[0], i[1])
print num_ran[c]
c = c + 1
raw_input()
cloud9
cloud9
Moderator

Posts : 38
Join date : 2014-04-09
Age : 34

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum