예제 #1
0
    class AI_creator:
        #get the photo from a selected library
        pic=open(##path to file##)
        #open it in photoshop or paint; your call
        paint=r'#path to file'
        subprocess.Popen("%s %s"%(paint,pic))
        #get photoshop or paint to add in a smudge onto the photo... randomly, flip a coin or something i dunno.
        coinflip=(randint(0,1))
        #figure out how to do that
        if coinflip==1:
            #defile image
            #state=1(true)
        else:
            #nothing

        #save the changes into a new library.
        pic.close()

#this will be the AI that will be trained to recognize an image is photoshopped or not.
    class AI_recognizer:
        #open the new photo in the new library
        #attempt to compare the new photo with the original and determine if its real or fake.
        #If it's real or fake, announce so.
        if state==1:
            print("Image is a poorly made fake!")
        else:
            print("Image is a genuine copy!")
        #do something, like mentally slap the user or something...
예제 #2
0
def crtprof():
    form = Userprofile()
    if request.method == "POST" and form.validate_on_submit():
        firstname = form.firstname.data
        lastname = form.lastname.data
        username = form.username.data
        gender = form.gender.data
        age = form.age.data
        biography = form.biography.data
        image = request.files['image']

        id = randint(00000000, 12345678)

        user = UserProfile(firstname, lastname, username, age, gender,
                           biography, image)
        db.session.add(user)
        db.session.commit()

        flash('Created profile successfully.', 'success')
        return redirect(url_for('view_profile'))
    else:
        flash('Profile not created', 'danger')

    flash_errors(form)
    return render_template('profile.html', form=form)
예제 #3
0
def part2():
    x = print(randint(1, 9))
       print("guess a number between 1 and 9")
       y = int(input("guess a number between 1 and 9"))
       while ( y != input("exit")):
       if x == y:
       print("you guessed exactly right")
       
       else if x < y:
       print("your number is too high")
       
       else if x > y:
       print("your number is too low")
    """
    Generate a random number between 1 and 9 (including 1 and 9). Ask the user
    to guess the number, then tell them whether they guessed too low, too high,
    or exactly right.
    (Hint: remember to use the user input lessons from the very first
    exercise).
    Keep the game going until the user types "exit".
    [ try checking the random module in python on google. Concepts: Infinite
    loops, if, else, loops and user/input].
    """


def part3(string):
    print("type a word")
       y = string(input("type a word"))
              if y == y[::-1]:
              print("is a palindrome")
              else:
              print("is not a palindrome")
    """
 def couper(self):
     c = randint(1, 50)
     PM = []
     for i in range(0, c):
         PM.append(self.paquet[0])
         self.paquet.pop(0)
     for i in range(0, len.PM):
         self.paquet.append(PM[0])
         PM.pop(0)
예제 #5
0
def random_select():
    """
    随机选择一组号码
    """
    red_balls = [x for x in range(1, 34)]
    selected_balls = []
    selected_balls = sample(red_balls, 6)
    selected_balls.sort()
    selected_balls.append(randint(1, 16))
    return selected_balls
예제 #6
0
 def start(self):
     print "you have to guess a natural number between 0 and 9"
     print "you have 3 chances, the random number won't change"
     rand = randint(1,9)
     for i in range (1, 3, 1)
         guess = int(raw_input("> "))
         if rand == guess:
             print "nice job!"
             return "final"
         else:
             print "try again"
     return "first"
예제 #7
0
Enter file contents herefrom random import randint 
 trials = 500 
 tracker = {2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0} 
 
 
 for i in range(trials): 
     roll = randint(1,6) + randint(1,6) 
     tracker[roll] = tracker[roll] + 1 
 
 
 for combination in tracker: 
     print "%s rolled %s times out of %." %(combination, tracker[combination], trials) 
     prob = float(tracker[combination])/trials 
     percent = prob*100 
     print "This is a probability of %s, or %s percent!" %(prob, percent) 
예제 #8
0
    UArray.append(Username)
    PArray.append(Password)

def Login():
    Username = input("Enter a username")
    for i in range (0, len(UArray)):
        if UArray[i] == Username:
            Password = ""
            while Password != PArray[i]:
                Password = input("Enter a password")
                LoggedIn = False
            LoggedIn = True


Count = 0   
while Count < 1 or Count > 3:
    Count = int(input("1.Circle\n2.Square\n3.Rectangle\nEnter number for shape:\n"))
print(Count)

if Count == 1:
    radius = randint(1,80)
    print("The Radius is " + radius)
    
    CArea = 3.14159265359 * radius * radius
    Options1= randint(radius-10,radius+10)
    Options2= randint(radius-10,radius+10)
    Options3= randint(radius-10,radius+10)
elif Count == 2:
    side = randint(1,80)
    SArea = side * side
예제 #9
0
>>> leeftijd-=1
>>> leeftijd
15
>>> if leeftijd < 18:
    hoelang_tot18jaar = 18 - leeftijd
    print('Over ' + str(hoelang_tot18jaar) + ' jaar wordt je 18')
elif leeftijd > 18:
    hoelang_al18jaar = leeftijd - 18
    print('Het is alweer ' + str(hoelang_al18jaar) + ' jaar geleden dat je 18 werd ;-)')
else:
    print('Je bent precies ' + str(leeftijd) + ' jaar')

    
Over 3 jaar wordt je 18
>>> from random import randint
randint(0,1000)
willekeurig_getal = randint(0,1000)
willekeurig_getal
print('Willekeurig getal tussen 0 en 1000: ' + str(willekeurig_getal))
SyntaxError: multiple statements found while compiling a single statement
>>> from random import randint
>>> randint(0,1000)
51
>>> willekeurig_getal = randint(0,1000)
>>> willekeurig_getal
265
>>> print('Willekeurig getal tussen 0 en 1000: ' str(willekeurig_getal))
SyntaxError: invalid syntax
>>> print('Willekeurig getal tussen 0 en 1000: ' + (willekeurig_getal))
Traceback (most recent call last):
  File "<pyshell#29>", line 1, in <module>
예제 #10
0
import sense_hat from SenseHat
import random from randint

sense = SenseHat()

message = "Hello, we are NMD!"
color = (randint(0,255),randint(0,255),randint(0,255))
no_color = (10,10,10)

sense.show_message(message, text_colour = no_color , back_colour = color)
예제 #11
0
 def shuffle_deck(self):
     for i in range(0, len(self.contents)):
         x = randint(0, 51)
         self.contents[i], self.contents[x] = self.contents[x], self.contents[i]
예제 #12
0
     def fill_board(self):
-        for y in xrange(BOARD_HEIGHT - 1, -1, -1):
-            for x in xrange(BOARD_WIDTH - 1, -1, -1):
+        for y in range(BOARD_HEIGHT - 1, -1, -1):
+            for x in range(BOARD_WIDTH - 1, -1, -1):
                 if self.board[x][y] != ITEM_NONE:
                     continue
-                for y2 in xrange(y - 1, -1, -1):
+                for y2 in range(y - 1, -1, -1):
                     if self.board[x][y2] != ITEM_NONE:
                         self.board[x][y] = self.board[x][y2]
                         self.extra_offset[x][y] = (0, ITEM_SIZE * (y2 - y))
@@ -683,7 +693,7 @@ class Game:
         system.blit(data.board, (24, 24))
         # Have a random piece blink
         c = randint(0, BOARD_WIDTH - 1), randint(0, BOARD_HEIGHT - 1)
-        if randint(0, 5) is 0 and not self.blink_list.has_key(c):
+        if randint(0, 5) is 0 and c not in self.blink_list:
             self.blink_list[c] = 5
         # Handle special scrolling cases
         if self.level_timer:
@@ -692,14 +702,14 @@ class Game:
             timer = self.board_timer
         else:
             timer = 0
-        if timer > SCROLL_DELAY / 2:
+        if timer > SCROLL_DELAY // 2:
             global_xoff = 0
             yoff = (SCROLL_DELAY - timer) * (SCROLL_DELAY - timer)
-            global_yoff = yoff * 50 * 50 / SCROLL_DELAY / SCROLL_DELAY
+            global_yoff = yoff * 50 * 50 // SCROLL_DELAY // SCROLL_DELAY
예제 #13
0
         from time import ctime
         time1 = ctime()
         await message.channel.send(time1)
     else:
         await message.channel.send('**OOPS**: Invalid or missing parameter: `<timezone>`. :x:')
 elif message.content.startswith('nv!slap'):
     target = message.content[len('*slap'):].strip()
     if target=='' or target==' ':
         await message.channel.send('**OOPS**: Missing parameter: `<target>` :x:')
     elif target=='me' or target=='Me':
         await message.channel.send('**OOPS**: Just. Don\'t. Even. Think. About. It. :x:')
     elif target=='Nevira' or target=='<@509848021630976011>' or target=='nevira':
         await message.channel.send('Why you slap me <@%s>...;-;' % message.author.id)
     elif target=='Josh' or target=='josh':
         from random import randint
         chance = randint(1,10)
         if chance==1:
             await message.channel.send('You revenged josh, by slapping him. With a **REAL** hand. :sunglasses:')
         else:
             await message.channel.send('**OOPS**: You failed. Now Josh slaps you back with a wallet, but no money comes out from it.')
     elif target=='<@!356456393491873795>' or target=='<@!440119103714361355>':
         await message.channel.send('**OOPS**: No. Just no. :x:')
     else:
         from random import randint
         chance = randint(1,10)
         if chance==1:
             await message.channel.send('**{0}** was slapped by **{1}**. Ouch...'.format(target, message.author))
         else:
             await message.channel.send('**OOPS**: You failed to slap {0}, now {1} is chasing you while you are running away from him/her.'.format(target, target))
 elif message.content.startswith('nv!dice_singular'):
     from random import randint
예제 #14
0
def random_row(board):
    return randint(0, len(board) - 1)
예제 #15
0
import random from randint

#create a list with user options
lst = [Rock, Paper, Scissor]

#System user choice
computer=t[randint(0,2)]

#player option
player=False

while player == False:
  player=input('Rock, Paper, Scissor?')
  
  if player == computer:
    print("Tie!")
  elif player == 'Rock':
      if computer == 'paper':
        print("You lose", computer, "covers", player)
      else:
        print("You Win", computer, "smashes", player)
  elif player == 'Paper':
      if computer == 'Scissor':
        print("You lose", computer, "cut", player)
      else:
        print("You Win", computer, "covers", player)
  elif player == 'Scissor':
      if computer == 'Rock':
        print("You lose", computer, "smashes", player)
      else:
예제 #16
0
def addingz(userinput_maxoperations):
	os.system('clear')
	quit = "0"
	lista = list()
	wrong_str = list()
	wrong_int = list()
	two_wrong_str_list = list()
	two_wrong_int_list = list()
	two_lista = list()


	#For loop to do math - 
	for line in range(int(userinput_maxoperations)):
		a = randint(1, 99)
		b = randint(1, 99)
		operation = a + b
		operation2 = str(a) + " + " + str(b) + ":"
		print operation2
		while True: 
			userinput_answer = raw_input("Answer: ")
			if re.search(r'(\w+[a-z]|\w+[A-Z])',userinput_answer):
				print "Is not a number!"
			elif len(userinput_answer.strip()) == 0 :
				print "No input"	
			elif userinput_answer in [',','<','@','!','~','#','$','%','^','&','*','-','_','=','+','?','>',',','.','/','`',':',';',"'"]:
				print "Try again"
			else:
				break
		userinput_answerToint = int(userinput_answer)
		if userinput_answerToint != operation:
			print "oops"
			print
			print
			wrong_int.append(operation)
			wrong_str.append(operation2)

	total_entered = len(lista)
	total_wrong = len(wrong_str)
	#total = int(total_entered)- int(total_wrong)
	userinput_maxoperations_int = int(userinput_maxoperations)
	wrong_str_lenght = len(wrong_str)
	total = userinput_maxoperations_int - wrong_str_lenght
	print "Calculating..."
	time.sleep(3)
	print "=================================================================="
	print "You got ", total , " out of ", userinput_maxoperations, " CORRECT!"
	print "------------------"
	print "Summary.... "
	time.sleep(2)
	print "Incorrect operations!"
	for lista_incorrecta in wrong_str:
		print lista_incorrecta
	print "Only : ",len(wrong_str)
	if len(wrong_str) == 0 :
		print "Congrats... You are done"
		time.sleep(2)
		os.system('clear')
	else:
		print	
		print
		print
		print "------------------------"
		time.sleep(5)
		os.system('clear')
		print "Let's try again with the ones you got incorrect: "
		##Function to to redo the incorrect ones
		def tryingagain():
			while True: 
				userinput_tryagain = raw_input("Answer: ")
				if re.search(r'(\w+[a-z]|\w+[A-Z])',userinput_tryagain):
					print "Is not a number!"
				elif len(userinput_tryagain.strip()) == 0 :
					print "No input"
				elif userinput_tryagain in [',','<','@','!','~','#','$','%','^','&','*','-','_','=','+','?','>',',','.','/','`',':',';',"'"]:
					print "Try again"
				else:
					break
			userinput_tryagain_int = int(userinput_tryagain)
			if userinput_tryagain_int != int(wrong_int_index):
				print "oops"
				print
				print
				two_wrong_str_list.append(wrong_str_index)
				two_wrong_int_list.append(wrong_int_index)
		i=0
		c=0 
		while i< total_wrong:
			wrong_str_index = str(wrong_str[i])
			wrong_int_index = str(wrong_int[c])
			print str(wrong_str[i])
			tryingagain()
			i+=1
			c+=1

		if len(two_wrong_str_list) == 0 :
			print "Congrats.... You are done"
			time.sleep(2)
			os.system('clear')
		else:
			print "Calculating...."
			time.sleep(5)
			os.system('clear')
			print "===================================="
			print "Incorrect operations:"
			print "-------"
			iii=0
			ccc=0
			for juniper in two_wrong_str_list:
				wrong_str_index = (two_wrong_str_list[iii])
				wrong_int_index = (two_wrong_int_list[ccc])
				print wrong_str_index
				iii+=1
				ccc+=1
			print
			print
			print
			print "You are almost done - Lets review the ones you still got incorrect!"
			ii=0
			cc=0
			total_wrong2 = len(two_wrong_str_list)

			while ii< total_wrong2:
				wrong_str_index2 = str(two_wrong_str_list[ii])
				wrong_int_index2 = str(two_wrong_int_list[cc])
				print wrong_str_index2
				invalid = True
				while invalid:
					userinput_tryagain1 = raw_input("Answer: ")
					if re.search(r'(\w+[a-z]|\w+[A-Z])',userinput_tryagain1):
						print "Is not a number!"
					elif len(userinput_tryagain1.strip()) == 0 :
						print "No input"
					elif userinput_tryagain1 == wrong_int_index2:
						print ("Good!")
						invalid = False
					else: 
						print ("try again")
						print
						print
						
				ii+=1
				cc+=1
			print ("You are now done!")
			os.system('clear')
예제 #17
0
import randint from random

ac=0
k=[5,20,50,100]
for ki in k:
	for i in range(8):
		x=randint(0,400)
		y=randint(0,400)
		klist,bac = grid.knn(ki,x,y)
		ac+=bac
	print ac/float(ki)
예제 #18
0
    def __init__(self, name):
    "The `constructor runs when we create a new thing"

        self.name = name
        self.jersey = randint(1, 99)
예제 #19
0
 def pitch_mph(____):
     mph = randint(50, 80)
     _____ mph 
예제 #20
0
파일: jokempó.py 프로젝트: batmit/Class
rom random import randint
from time import sleep
n = int(input('Pedra[0]\nPapel[1]\nTesoura[2]\n:'))
xo = sleep(2)
com = randint(0, 2)
print('-=-' * 20)
if n == 0:
  print('Você jogou pedra')
  if com == 0:
    print('O computador jogou pedra')
    print('Empate')
  elif com == 1:
    print('O computador jogou papel')
    print('Você perdeu')
  elif com == 2:
    print('O computador jogou tesoura')
    print('Você ganhou')
elif n == 1:
  print('Você jogou papel')
  if com == 0:
    print('O computador jogou pedra')
    print('Você ganhou')
  elif com == 1:
    print('O computador jogou papel')
    print('Empate')
  elif com == 2:
    print('O computador jogou tesoura')
    print('Você perdeu')
elif n == 2:
  print('Você jogou tesoura')
  if com == 0:
예제 #21
0
    print num ** 2
    num += 1

    #using while to check simple errors
    choice = raw_input('Enjoying the course? (y/n)')

while choice != 'y' and choice != 'n':  # Fill in the condition (before the colon)
    choice = raw_input("Sorry, I didn't catch that. Enter again: ")



#game using while
m random import randint

# Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)

guesses_left = 3
# Start your game!

while guesses_left > 0:
    print 'You got %s guesses left' % guesses_left
    guess = int(raw_input('Guess a number (1-10):'))

    if guess == random_number:
        print 'You win!'
        break
    guesses_left -= 1
else:
    print 'You lose.'
예제 #22
0
def divisionz(userinput_maxoperations):

	i = datetime.now()
	e = i.strftime('%H:%M:%S')

	os.system('clear')
	quit = "0"
	lista = list()
	wrong_str = list()
	wrong_int = list()
	two_wrong_str_list = list()
	two_wrong_int_list = list()
	two_lista = list()
	print """
	**********************************************************
			READ BEFORE PROCEEDING!!!!!

		***********************************
		*	Round to the NEAREST 10   *
		***********************************


	For example:
	89 / 9 = 9

	The nearest 10 could be either 80 or 90 , right?

	** The correct answer is 9

	That is because 9 * 9 is equals to 81 which is the nearest 10 to 89 is 90

	**********************************************************
	"""
	print 
	print 

	enteruser = raw_input("Press ENTER to continue")


	#For loop to do math - 
	for line in range(int(userinput_maxoperations)):
		a = randint(1,90)
		b = randint(2,9)
		operation = a / b
		operation2 = str(a) + " / " + str(b) + ":"
		print operation2

		while True: 
			userinput_answer = raw_input("Answer: ")
			if re.search(r'(\w+[a-z]|\w+[A-Z])',userinput_answer):
				print "Is not a number!"
			elif len(userinput_answer.strip()) == 0 :
				print "No input"
			elif userinput_answer in ['<','@','!','~','#','$','%','^','&','*','-','_','=','+','?','>',',','.','/','`',':',';',"'"]:
				print "Try again"
			else:
				break
		userinput_answerToint = int(userinput_answer)
		if userinput_answerToint != operation:
			print "oops"
			print
			print
			wrong_int.append(operation)
			wrong_str.append(operation2)

	total_entered = len(lista)
	total_wrong = len(wrong_str)
	#total = int(total_entered)- int(total_wrong)
	userinput_maxoperations_int = int(userinput_maxoperations)
	wrong_str_lenght = len(wrong_str)
	total = userinput_maxoperations_int - wrong_str_lenght
	print "Calculating..."
	time.sleep(3)
	print "=================================================================="
	print "You got ", total , " out of ", userinput_maxoperations, " CORRECT!"
	print "------------------"
	print "Summary.... "
	time.sleep(2)
	print "Incorrect operations!"
	for lista_incorrecta in wrong_str:
		print lista_incorrecta
	print "Only : ",len(wrong_str)
	if len(wrong_str) == 0 :
		print "Congrats... You are done"
		time.sleep(2)
	else:
		print	
		print
		print
		print "------------------------"
		time.sleep(5)
		os.system('clear')
		print "Let's try again with the ones you got incorrect: "
		##Function to to redo the incorrect ones
		def tryingagain():
			while True: 
				userinput_tryagain = raw_input("Answer: ")
				if re.search(r'(\w+[a-z]|\w+[A-Z])',userinput_tryagain):
					print "Is not a number!"
				elif len(userinput_tryagain.strip()) == 0 :
					print "No input"
				elif userinput_tryagain in ['<','@','!','~','#','$','%','^','&','*','-','_','=','+','?','>',',','.','/','`',':',';',"'"]:
					print "Try again"
				else:
					break
			userinput_tryagain_int = int(userinput_tryagain)
			if userinput_tryagain_int != int(wrong_int_index):
				print "oops"
				print
				print
				two_wrong_str_list.append(wrong_str_index)
				two_wrong_int_list.append(wrong_int_index)
		i=0
		c=0 
		while i< total_wrong:
			wrong_str_index = str(wrong_str[i])
			wrong_int_index = str(wrong_int[c])
			print str(wrong_str[i])
			tryingagain()
			i+=1
			c+=1
		if len(two_wrong_str_list) == 0 :
			print "Congrats.... You are done"
			time.sleep(2)
			os.system('clear')
		else:
			print "Calculating...."
			time.sleep(5)
			os.system('clear')
			print "===================================="
			print "Incorrect operations:"
			print "-------"
			iii=0
			ccc=0
			for juniper in two_wrong_str_list:
				wrong_str_index = (two_wrong_str_list[iii])
				wrong_int_index = (two_wrong_int_list[ccc])
				print wrong_str_index
				iii+=1
				ccc+=1
			print
			print
			print
			print "You are almost done - Lets review the ones you still got incorrect!"
			ii=0
			cc=0
			total_wrong2 = len(two_wrong_str_list)

			while ii< total_wrong2:
				wrong_str_index2 = str(two_wrong_str_list[ii])
				wrong_int_index2 = str(two_wrong_int_list[cc])
				print wrong_str_index2
				invalid = True
				while invalid:
					userinput_tryagain1 = raw_input("Answer: ")
					if re.search(r'(\w+[a-z]|\w+[A-Z])',userinput_tryagain1):
						print "Is not a number!"
					elif len(userinput_tryagain1.strip()) == 0 :
						print "No input"
					elif userinput_tryagain1 == wrong_int_index2:
						print ("Good!")
						invalid = False
					else: 
						print ("try again")
						print
						print
						
				ii+=1
				cc+=1
			print ("You are now done!")
예제 #23
0
# session.add_all(user_list)
# session.commit()
# session.close()

list=session.query(User).all();
list=session.query(User.name).all();
list=session.query(User).filter(User.name=='a').all()
list=session.query(User).filter(User.id>7,User.name.in_(['a','b'])).all()
list=session.query(User).filter(User.name.like('%c')).all()
list=session.query(User).filter(or_(User.name == 'c',User.id==7)).all()
list=session.query(User).order_by(User.id.desc())
print(session.query(func.count('1')).select_from(User).scalar())
print(session.query(func.count(User.id)).filter(User.id > 7 ).scalar())

#批量新增
session.execute(
    User.__table__.insert(),
    [{'name': randint(1, 100),'password': randint(1, 100)} for i in range(10000)]
)
session.commit()


# for x in list:
#     print(x.name)






rom random import randint

i = 0
while True:
    bil = randint(0,10)
    print(bil)
    i = i + 1
    if bil == 5:
        break
print('Jumlah perulangan :' + str(i))
예제 #25
0
 def date_joined(self):
     return dt.datetime.now() - dt.timedelta(days=randint(5, 50))
예제 #26
0
rom random import randint

num_range = 0, 20
secret_num = randint(*num_range)

while True:
    try:
        user_num = int(
            input(f'Guess a number between {num_range[0]}-{num_range[1]}: '))
        if user_num > secret_num:
            print('Too high...')
        elif user_num < secret_num:
            print('Too low...')
        else:
            print('Hit!')
            break
    except ValueError:
        print('Please input a valid number!')
    print()
예제 #27
0
import random from randint 

answer = randint(0,100+1)
print(answer) 

count = 1

def compare_guess():
    while count <= 3:
        guess = int(input('Hi, guess the num(1~100)'))
        if answer == guess:
            print("You guesses correct Number bro!")
            break
        else:
            print("You messed up with guess bro! Try again mate!") 

        count = count + 1 

compare_guess()

예제 #28
0
def random_col(board):
    return randint(0, len(board[0]) - 1)
예제 #29
0
def random_row(board):
    return randint(0, len(board) - 1)
예제 #30
0
#!/usr/bin/env python# -*- coding:utf-8 -*-
import requestsimport argparse, jsonfrom random import randint

USAGE = './dzscan.py [options]'

HEADERS = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36", "X-Forwarded-For": '%s:%s:%s:%s' % (randint(1, 255),               randint(1, 255), randint(1, 255), randint(1, 255)), "Content-Type": "application/x-www-form-urlencoded", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Connection": "keep-alive"}

def parseCmd(): """    @cmdline parser """
    parser = argparse.ArgumentParser(usage=USAGE, formatter_class=argparse.RawTextHelpFormatter, add_help=False)
    parser.add_argument('-u', '--url', dest='url', help='The Discuz! URL/domain to scan.')
    parser.add_argument('--gevent', dest='gevent', metavar='<number of gevent>', help='The number of gevents to use when multi-requests')
    parser.add_argument('-f', '--force', dest='force', action='store_true', default=False, help='Forces DzScan to not check if the remote site is running Discuz!')
    parser.add_argument('-h', '--help', action='help',  help='Show help message and exit.')
    parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Show verbose message during scaning')
    parser.add_argument('--update', dest='update', action='store_true', default=False, help='Update database to the latests version.')
    parser.add_argument('--log', dest='log', action='store_true', default=False, help='Record scan output in .log file')
    args = parser.parse_args() return args.__dict__

def banner(): """    @dzscan banner """ str = """_______________________________________________________________          Dizscan! Security Scanner by the DzScan Team    Version 0.2    http://dzscan.org wyc@Dzscan_______________________________________________________________ """ print str

def examine(content): if '' not in content and len(content) > 1000 \ and 'http://error.www.xiaomi.cn' not in content: return True return False

def fetch_vul(addon):    ids = set()    url = 'http://dzscan.org/index.php/welcome/view?plugin=%s' % addon    json_data = json.loads(requests.get(url).content) for vul in json_data:        ids.add(vul['id']) return ids
예제 #31
0
def random_col(board):
    return randint(0, len(board[0]) - 1)
예제 #32
0
	print(random())

	
0.8444218515250481
0.7579544029403025
0.420571580830845
0.25891675029296335
0.5112747213686085
>>> from random import randrange, randint
>>> print(randrange(1))
0
>>> print(randrange(0,1))
0
>>> print(randrange(0,1,1,))
0
>>> print(randint(0,0))
0
>>> print(randrange(2))
0
>>> print(randrange(2))
0
>>> print(randrange(35))
18
>>> print(randint(1,25))
5
>>> 
				 
SyntaxError: invalid syntax
>>> from platform import platform
>>> platform(1)
'Windows-10-10.0.19041-SP0'
예제 #33
0
import random import randint
from time import sleep

def sorteio(lista)
    print('Sorteio de 5 valores da lista: ', end='')
    for cont in range(0, 5):
       n =randint(1, 10)
       lista.append(n)
       print(f'{n}', end=', flush=true)

def somaPar(lista):
    soma = 0
    for valor in lista:
        if valor & 2 == 0
예제 #34
0
-from random import randint
-
-board = []
-
-for x in range(5):
-    board.append(["O"] * 5)
-
-def print_board(board):
-    for row in board:
-        print " ".join(row)
-
-print "Let's play Battleship!"
-print_board(board)
-
-def random_row(board):
-    return randint(0, len(board) - 1)
-
-def random_col(board):
-    return randint(0, len(board[0]) - 1)
-
-ship_row = random_row(board)
-ship_col = random_col(board)
-print ship_row
-print ship_col
-
-# Everything from here on should go in your for loop!
-# Be sure to indent four spaces!
-for turn in range(4):
-    guess_row = int(raw_input("Guess Row:"))
-    guess_col = int(raw_input("Guess Col:"))
-
예제 #35
0
def fortune_picker(fortune_number): # A function definition statement that has a parameter `fortune_number`
    if fortune_number == 1:
        return 'You will have six children'
    elif fortune_number == 2:
        return 'You will become very wise'
    elif  fortune_number == 3:
        return 'A new friend will help you find yourself'
    elif fortune_number == 4:
        return 'Do not eat the sushi'
    elif fortune_number == 5:
        return 'That promising venture... it is a trap.'
    elif fortune_number == 6: 
        return 'Sort yourself out then find love.'

random_number = randint(1, 6) # Choose a random number between 1 and 6 and assign it to a new variable `random_number`
print(fortune_picker(random_number))

## Local and Global Scope

We have seen that [functions](https://docs.tdm-pilot.org/key-terms/#function) make maintaining code easier by avoiding duplication. One of the most dangerous areas for duplication is [variable](https://docs.tdm-pilot.org/key-terms/#variable) names. As programming projects become larger, the possibility that a [variable](https://docs.tdm-pilot.org/key-terms/#variable) will be re-used goes up. This can cause weird errors in our programs that are hard to track down. We can alleviate the problem of duplicate [variable](https://docs.tdm-pilot.org/key-terms/#variable) names through the concepts of [local scope](https://docs.tdm-pilot.org/key-terms/#local-scope) and [global scope](https://docs.tdm-pilot.org/key-terms/#global-scope).

We use the phrase [local scope](https://docs.tdm-pilot.org/key-terms/#local-scope) to describe what happens within a [function](https://docs.tdm-pilot.org/key-terms/#function). The [local scope](https://docs.tdm-pilot.org/key-terms/#local-scope) of a [function](https://docs.tdm-pilot.org/key-terms/#function) may contain [local variable](https://docs.tdm-pilot.org/key-terms/#local-variable), but once that [function](https://docs.tdm-pilot.org/key-terms/#function) has completed the [local variable](https://docs.tdm-pilot.org/key-terms/#local-variable) and their contents are erased. 

On the other hand, we can also create [global variables](https://docs.tdm-pilot.org/key-terms/#global-variable) that persist at the top-level of the program *and* within the [local scope](https://docs.tdm-pilot.org/key-terms/#local-scope) of a [function](https://docs.tdm-pilot.org/key-terms/#function).

* In the [global scope](https://docs.tdm-pilot.org/key-terms/#global-scope), [Python](https://docs.tdm-pilot.org/key-terms/#python) does not recognize any [local variable](https://docs.tdm-pilot.org/key-terms/#local-variable) from within [functions](https://docs.tdm-pilot.org/key-terms/#function)
* In the [local scope](https://docs.tdm-pilot.org/key-terms/#local-scope) of a [function](https://docs.tdm-pilot.org/key-terms/#function), [Python](https://docs.tdm-pilot.org/key-terms/#python) can recognize and modify any [global variables](https://docs.tdm-pilot.org/key-terms/#global-variable)
* It is possible for there to be a [global variable](https://docs.tdm-pilot.org/key-terms/#global-variable) and a [local variable](https://docs.tdm-pilot.org/key-terms/#local-variable) with the same name

Ideally, [Python](https://docs.tdm-pilot.org/key-terms/#python) programs should limit the number of [global variables](https://docs.tdm-pilot.org/key-terms/#global-variable) and create most [variables](https://docs.tdm-pilot.org/key-terms/#variable) in a [local scope](https://docs.tdm-pilot.org/key-terms/#local-scope).