You are viewing our Forum Archives. To view or take place in current topics click here.
Python Palooza- Sources Sauce and Strings
Posted:

Python Palooza- Sources Sauce and StringsPosted:

Invicies
  • Challenger
Status: Offline
Joined: Jul 18, 201212Year Member
Posts: 108
Reputation Power: 4
Status: Offline
Joined: Jul 18, 201212Year Member
Posts: 108
Reputation Power: 4
Installation guide for python: (Windows Only)
[spoiler]
1.) First thing you need to do is visit [ Register or Signin to view external links. ] and download the Windows installer.

Download Link: [ Register or Signin to view external links. ]

2.) After downloading the install file, locate it, right click and choose Install

3.) The first window that shows up gives you the choice of who to install python for.



4.) The second window is asking you where you would like python installed. Default
directory is C:\Python25\ but I have seen many people shorten it to C:\Py\ or C:\Python\.



5) The third window is asking you how you would want python installed. You can
make your own judgements here but I suggest just clicking Next.




6.) Thats it!!! At this point you should see it go through the installation process. Click Finish
when it is complete.

Now that python is installed lets go download a python script and run it.

1.) First we find a python script and save it with the extension .py
In the picture you can see we found a joomla scanner and saved it as joomlascan.py in our
Python directory C:\Python25



2.) Now lets run the command prompt by going to Start >> Run and typing cmd.exe and hitting Enter
Your command prompt (cmd.exe) should load and be ready for commands.


3.) Now we need to move to where we installed python (C:\Python25) with the cd command.
After typeing cd C:\Python25 and hitting Enter you should see.

C:\Python25>_

4.) At this point you can use the dir command to view the files but we already know joomlascan.py is
in this directory.

5.) To run the script all you have to type is: python joomlascan.py
[/spoiler]
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Random Source Codes: (Both advanced and basic)

Guessing Game
[spoiler]

import random
import os
os.system("clear")
a = 0
g = 0
l = 1
b = ["1","2","3","4","5","6","7","8","9","10"]
c = random.choice(B)/>/>
while l == 1:
os.system("clear")
print "1) Single Player"

[/spoiler]

Magic 8 Ball (Added option ;P)
[spoiler]

import os
os.system("clear")
loop = 1
while loop == 1:
import random
raw_input("Ask your question: ")
a = ["Yes","No","Ask Again Later","Go die","Maybe"]
p = random.choice(a)
print(p)

[/spoiler]

Retro Pong
[spoiler]

#! /usr/bin/python

import Tkinter, thread, time, math, threading

Sema = threading.Semaphore(1)
RectList = (0, 0)

class MyRect:
def __init__(self, mycan, x1, y1, x2, y2, col):
self.x1 = x1
self.y1 = y1

[/spoiler]

Rock,Paper,Scissors
[spoiler]

import random
import os
c1 = 0
a = ['1', '2', '3']
p = random.choice(a)
c2 = 0
c3 = 0
l = 1
while l == 1:
a = ['1', '2', '3']
p = random.choice(a)
os.system("clear")
print "Your Options Are: "
print "1) Scissors"
print "2) Paper"
print "3) Rock"
x = raw_input("Make Your Choice: ")
if x == p:
print "You Win!"
if x != p:
print "You Lose!"
raw_input("Press Enter To Continue")
os.system("clear")

[/spoiler]

Flip a Coin
[spoiler]

import random,os,time
os.system("clear")
print '1) Low'
print '2) High'
z = int(raw_input('How high do you want to flip the coin: '))
if z == 1:
qz = 2
if z ==2:
qz = 5
x = 0
x = x + 1
time.sleep(0.2)
b = ' @@@@@ ',' @ @ ',' @ O O @ ' ,' @ ___ @ ',' @ @ ',' @@@@@ '
q = ' |',' |',' |',' |',' |',' |'
a = ' @@@@@ ',' @|/ \|@ ',' @ |/ \| @ ' ,' @ |/ \| @ ',' @|/ \|@ ',' @@@@@ '
c = [a,b]
os.system("clear")
for x in xrange(qz):
os.system("clear")
print "\n".join(q)
time.sleep(0.2)
os.system("clear")
time.sleep(0.2)
print "\n".join(random.choice(c))
time.sleep(0.2)

[/spoiler]

City of Warscape (Text-Based)
[spoiler]

def a(classname,highdamageweaponname,lowdamageweaponname,ldmgname,hdmgname,yourhealth,enemyhealth,ldmgspellname,hdmgspellname):
import os
import random
os.system("clear")
monsters = ['cyclopse', 'duck', 'dragon', 'wizard', 'magician']
randommonster = random.choice(monsters)
print "Class: %s" % classname
print "1) %s (More damage, but less armor)" % highdamageweaponname
print "2) %s (Less damage, but more armor)" % lowdamageweaponname
a = int(raw_input("You are battling a %s what weapon do you want?: " % randommonster))
while enemyhealth >= -1 and yourhealth >= -1:
hdmg = [0,5,0,15,0,20,30]
ldmg = [0,5,6,7,8,9,10]
ldmgrandom = random.choice(ldmg)
hdmgrandom = random.choice(hdmg)
edmg = [ldmgrandom,hdmgrandom]
edmgrandom = random.choice(edmg)
mdmg = [1,2,3]
mdmgrandom = random.choice(mdmg)
os.system("clear")
if a == 1:
print "you have chosen a %s" % highdamageweaponname
print "Your Armor: ", yourhealth
print "Enemy Armor: ", enemyhealth
print "1) %s (High damage | High chance of missing)" % hdmgname
print "2) %s (Low damage | Low chance of missing)" % ldmgname
c = int(raw_input("Choose your attack: "))
if c == 1:
ddmg = hdmgrandom
yourhealth = yourhealth - edmgrandom
enemyhealth= enemyhealth- ddmg
print "You Did ", ddmg, "Damage"
raw_input("Press Enter To Continue")
elif c == 2:
ddmg = hdmgrandom
yourhealth = yourhealth - edmgrandom
enemyhealth= enemyhealth- ddmg
print "You Did ", ddmg, "Damage"
raw_input("Press Enter To Continue")
if a == 2:
print "you have chosen a %s" % lowdamageweaponname
print "Your Armor: ", yourhealth + 20
print "Enemy Armor: ", enemyhealth
print "1) %s (High damage | High chance of missing)" % hdmgspellname
print "2) %s (Low damage | Low chance of missing)" % ldmgspellname
c = int(raw_input("Choose your attack: "))

if c == 1:
ddmg = hdmgrandom
yourhealth = yourhealth - edmgrandom
enemyhealth= enemyhealth- (ddmg - mdmgrandom)
print "You Did ", ddmg, "Damage"
raw_input("Press Enter To Continue")
elif c == 2:
ddmg = ldmgrandom
yourhealth = yourhealth - edmgrandom
enemyhealth= enemyhealth- (ddmg - mdmgrandom)
print "You Did ", ddmg, "Damage"
raw_input("Press Enter To Continue")
if c > 2 or c < 1:
print "Invalid attack"
raw_input("Press Enter To Continue")
if yourhealth <= 0:
os.system("clear")
print "You Died..."

elif enemyhealth<= 0:
os.system("clear")
print "You Killed Him!"
def menu():
import os
import random
os.system("clear")
print "############################################"
print " City of Warscape "
print "###########################################"
print " "
print "Choose Your Class"
print "1) Warrior"
print "2) Ranger"
print "3) Mage"
x = int(raw_input("What Class What You Like To Be?: "))
if x == 1:
a('Warrior','Mace','Sword','Pound','Bash',100,100,'Slice','Dice')
if x == 2:
a('Ranger','Bow','Knives','Steady Shot','Power Shot',100,100,'Toss','Hurl')
if x == 3:
a('Mage','Staff','Wand','Poke','Slash',100,100,'Fireball','Froststrike')
menu()

[/spoiler]

Strong password generator
[spoiler]

#Arch3r's Password generator
#
#Generates passwords based on characters & number to be created

#Importing modules
import random

#defining alphabet characters as list
alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","z"]

#Defining program variables
character = 0
loop = 0
#Welcome Message
print "Created by ???"

#Creating .txt file to dump passwords in
file_name = raw_input("\nName of file to dump passwords into: ")
file_name = file_name + ".txt"
wordlist = open(file_name, "a")
print "\n------------------------------------------------------"
#Defining program variables
loop = 0
loop1 = 0
letter = 0
character = 0
amount = 0

while loop == 0:
character = input("\nHow many characters does your password contain: ")
amount = input("\nHow many passwords do you wish to generate: ")
while loop1 <> amount:
loop2 = 0
password = ""
while loop2 <> character:
x = random.randrange(25)
letter = alphabet[x]
password = password + letter
loop2 = loop2 + 1
password = password + "\n"
loop1 = loop1 + 1
wordlist.writelines(password)
again = raw_input("\n\nType 'Exit' to quit or type 'again' to repeat ")
if "exit" in again:
loop = 1
wordlist.close
print "\n------------------------------------------------------"
print "Advanced program Visu"

[/spoiler]

Tic Tac Toe
[spoiler]

#Tic Tac Toe

import time, random

#This draws the game
def tablero():
filas = "+--"*3+"+\n"
columnas = "| "*3+"|\n"
return (filas + columnas*2)*3 + filas

#this draws X and O
#jugada = move, play
#tipo = X or O
def tableroJugando(tabDibujado, jugada, tipo):
if jugada == 1:
tabDibujado[23]=tipo
return "".join(tabDibujado)
if jugada == 2:
tabDibujado[29] = tipo
return "".join(tabDibujado)
if jugada == 3:
tabDibujado[35] = tipo
return "".join(tabDibujado)
if jugada == 4:
tabDibujado[83] = tipo
return "".join(tabDibujado)
if jugada == 5:
tabDibujado[89] = tipo
return "".join(tabDibujado)
if jugada == 6:
tabDibujado[95] = tipo
return "".join(tabDibujado)
if jugada == 7:
tabDibujado[143] = tipo
return "".join(tabDibujado)
if jugada == 8:
tabDibujado[149] = tipo
return "".join(tabDibujado)
if jugada == 9:
tabDibujado[155] = tipo
return "".join(tabDibujado)

#Function that see who is the winner
def ganar(ocupados, ocupables):
counter = 0
verificador = True
while verificador == True:
for i in range(8):
counter = 0
for ocupado in ocupados:
if ocupado in ocupables[i]:
counter += 1
if counter == 3:
return True
verificador = False
break
return False
verificador = False
break

#You choose X or O
def elegir():
while True:
player = raw_input("\nChoose X or O: ").upper()
if player == "X" or player == "O":
break
else:
print "Choose X or O"
print "You chose %s\n\n" % player
return player

#FThis chooses player2 X or O
def elegirJug2(player1):
if player1 == "X":
player2 = "O"
else:
player2 = "X"
return player2

#Function that sees if the square has already an X or O
def verificar(casillero, ocupados1, ocupados2, op = "pvnp"):
numeros = "123456789"
if op != "pvnp":
if casillero in ocupados1 or casillero in ocupados2:
print "\nYou cant draw here"
print "please choose another square\n"
return False
else:
if str(casillero) in numeros:
return True
else:
print "Number from 1 to 9\n"
return False
else:
if casillero in ocupados1 or casillero in ocupados2:
return False
else:
return True

#Which player start
def quienparte():
print "Who start"
resultado = random.randint(1,2)
while True:
eleccion = int(input("Choose (1) or (2): "))
if eleccion == 1 or eleccion == 2:
break
else:
print "1 or 2 please"
if eleccion == resultado:
print "You start, you are lucki!\n"
return True
else:
print "Sorry you dont start :(/>\n"
return False

def IA():
primeros = [1,3,7,9]
if len(p2) > 1:
ataque = ataqueIA(p2, ganadores)
if ataque != False:
for i in ataque:
if verificar(i, p1, p2) == True:
return i
break
defensa = defensaIA(p1, ganadores, noUse)
if defensa != False:
for i in defensa:
z = False
if verificar(i, p1, p2) == True:
return i
z = True
break
if z == False:
ocup.extend(defensa)
try:
defensa = defensaIA(p1, ganadores, noUse, ocup)
except:
for i in range(1,10):
if i in p1 or i in p2:
pass
else:
return i
elif 1 in primeros:
for i in primeros:
if i in p1 or i in p2:
primeros.remove(i)
return primeros[random.randint(0, len(primeros)-1)]
elif verificar(5, p1, p2) == True:
return 5
else:
for i in range(1,10):
if i in p1 or i in p2:
pass
else:
return i

#is how AI defends
def defensaIA(ocupados1, ocupables, noUsar, ocupados2=None):
counter = 0
counter2 = 0
verificador = True
while verificador == True:
for i in range(8):
counter = 0
try:
nousable = noUsar[0]
except:
nousable = None
if ocupados2 == None and nousable == None or nousable == noUsar[0]:
for ocupado in ocupados1:
if ocupado in ocupables[i]:
counter += 1
if counter == 2:
return ocupables[i]
verificador = False
break
else:
while True:
for i in ocupados2[:2]:
if i in ocupados1:
counter+=1
if counter == 2:
noUsar.append(ocupados2)
ocupados2 = None
if ocupados2 == None:
break
counter = 0
for i in ocupados2[-2:]:
if i in ocupados1:
counter+=1
if counter == 2:
noUsar.append(ocupados2)
ocupados2 = None
if ocupados2 == None:
break
counter = 0
for i in ocupados2[::2]:
counter+=1
if i in ocupados1:
noUsar.append(ocupados2)
ocupados2 = None
if ocupados2 == None:
break
return False
verificador = False
break

#How AI attack, is the same logic of the defense
def ataqueIA(ocupados2, ocupables):
counter = 0
verificador = True
while verificador == True:
for i in range(8):
counter = 0
for ocupado in ocupados2:
if ocupado in ocupables[i]:
counter+=1
if counter ==2:
return ocupables[i]
break
return False
verificador = False
break

def contraQuien():
while True:
respuesta = int(input("1.- player vs player?\n2.- player vs el PC?\nelige 1 o 2: "))
if respuesta == 1:
return "pvp"
break
if respuesta == 2:
return "pvnp"
break
else:
print "1 or 2 please"

#winner lines
ganadores = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[3,5,7],[1,5,9]

tab = list(tablero())

print "Tic Tac Toe =)"
time.sleep(1)
print "\n\n"
print tablero()
print "\nsquare 1 is top right corner"
print "square 2 is top center, square 3 ...."
time.sleep(3)
print "\n\nLets start ..."

oponente = contraQuien()

#Elegimos X o O para player1 y 2
player1 = elegir()
player2 = elegirJug2(player1)

#squares of player1 and 2
p1 = []
p2 = []

#Tenemos los que ocupamos y los que no se pueden usar, para la defensa.
ocup = []
noUse = []

#who starts
if quienparte() == True:
jugador = 1
else:
jugador = 2

#main loop
while True:
if jugador == 1:
while True:
elije = int(input("player1: "))
if verificar(elije, p1, p2) == True:
break
p1.append(elije)
print tableroJugando(tab, elije, player1)
jugador = 2
if ganar(p1, ganadores) == True:
print "Yo win!!"
denuevo = raw_input("want to play again? (Y/N): ").upper()
if denuevo == "Y":
print "good choice =)\n\n"
print tablero()
p1 = []
p2 = []
if quienparte() == True:
jugador = 1
else:
jugador = 2
tab = list(tablero())
player1 = elegir()
player2 = elegirJug2(player1)
else:
print "OK, bye"
break
if jugador == 2:
if oponente == "pvp":
while True:
elije = int(input("Player 2: "))
if verificar(elije, p1, p2) == True:
break
if oponente == "pvnp":
elije = IA()
p2.append(elije)
time.sleep(1)
print tableroJugando(tab, elije, player2)
jugador = 1
if ganar(p2, ganadores) == True:
if oponente == "pvp":
print "Player 2 ...\nY o u w i n ! ! !"
if oponente == "pvnp":
print "You loose with the PC !!!"
break

[/spoiler]

NOTE: The entire strings for each Program are not Complete, finish them yourself.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.