我正在做一个大学项目,开始时打印出两个给定输入之间的所有素数。后来我被告知它必须与我的课程网络管理有点相关,所以我想在我的脚本末尾添加一个密码生成器(用于网络安全)
我已经写出了所有代码,但是我遇到了一个问题,它无法在我打印出的列表中使用随机素数。它只使用打印的最后一个数字,我理解为什么,但无论如何我可以做到这一点,以便使用随机素数还是我必须将这些数字存储在某个地方?
#A program to count the prime numbers from a given start to a given end
#importing math function
import math
import os, random, string
#Input the number to start counting from
Starting_number = input("Enter the starting number: ")
#Input the number to end the count on.
Ending_number = input("Enter the number you want to count up to: ")
#if Starting_number is less than 0 it will print out a suitable message.
if Starting_number < 0:
print 'Invalid entry, please enter a positiv number. \nWill count from ',Starting_number, 'to 0 and begin prime number count to',Ending_number, '.'
#If Ending_number is less than or equals to 0 then it will print out a suitable message.
if Ending_number <= 0:
print 'Invalid entry on last input \nPlease enter two positive numbers for the count to work.'
#Starting loop as long as the current count is between Starting_number and Ending_number
for num in range(Starting_number, Ending_number):
#
if all(num%i !=0 for i in range(2,num)):
print num
if num >= 1 and num <= 100:
length = 4
chars = string.ascii_letters + string.digits + '!@#$%^&*()'
random.seed = (os.urandom(1024))
print ''.join(random.choice(chars) for i in range(length))
if num >= 101 and num <= 200:
length = (Ending_number / Starting_number) * 5 + 11
if length >= num:
length = num / 100
chars = string.ascii_letters + string.digits + '!@#$%^&*()'
random.seed = (os.urandom(1024))
print ''.join(random.choice(chars) for i in range(length))